1; This test ensures that IVUsers works correctly in the legacy pass manager 2; without LCSSA and in the specific ways that some of its users (LSR) require. 3; 4; FIXME: We need some way to match the precision here in the new PM where loop 5; passes *always* work on LCSSA. This should stop using a different set of 6; checks at that point. 7 8; RUN: opt < %s -analyze -iv-users | FileCheck %s --check-prefixes=CHECK,CHECK-NO-LCSSA 9; RUN: opt < %s -disable-output -passes='print<ivusers>' 2>&1 | FileCheck %s 10 11; Provide legal integer types. 12target datalayout = "n8:16:32:64" 13 14; The value of %r is dependent on a polynomial iteration expression. 15; 16; CHECK-LABEL: IV Users for loop %foo.loop 17; CHECK-NO-LCSSA: {1,+,3,+,2}<%foo.loop> 18define i64 @foo(i64 %n) { 19entry: 20 br label %foo.loop 21 22foo.loop: 23 %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %foo.loop ] 24 %indvar.next = add i64 %indvar, 1 25 %c = icmp eq i64 %indvar.next, %n 26 br i1 %c, label %exit, label %foo.loop 27 28exit: 29 %r = mul i64 %indvar.next, %indvar.next 30 ret i64 %r 31} 32 33; PR15470: LSR miscompile. The test1 function should return '1'. 34; It is valid to fold SCEVUnknown into the recurrence because it 35; was defined before the loop. 36; 37; SCEV does not know how to denormalize chained recurrences, so make 38; sure they aren't marked as post-inc users. 39; 40; CHECK-LABEL: IV Users for loop %test1.loop 41; CHECK-NO-LCSSA: %sext.us = {0,+,(16777216 + (-16777216 * %sub.us))<nuw><nsw>,+,33554432}<%test1.loop> (post-inc with loop %test1.loop) in %f = ashr i32 %sext.us, 24 42define i32 @test1(i1 %cond) { 43entry: 44 %sub.us = select i1 %cond, i32 0, i32 0 45 br label %test1.loop 46 47test1.loop: 48 %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test1.loop ] 49 %inc11.us = add nsw i32 %inc1115.us, 1 50 %cmp.us = icmp slt i32 %inc11.us, 2 51 br i1 %cmp.us, label %test1.loop, label %for.end 52 53for.end: 54 %tobool.us = icmp eq i32 %inc1115.us, 0 55 %mul.us = shl i32 %inc1115.us, 24 56 %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us 57 %sext.us = mul i32 %mul.us, %sub.cond.us 58 %f = ashr i32 %sext.us, 24 59 br label %exit 60 61exit: 62 ret i32 %f 63} 64 65; PR15470: LSR miscompile. The test2 function should return '1'. 66; It is illegal to fold SCEVUnknown (sext.us) into the recurrence 67; because it is defined after the loop where this recurrence belongs. 68; 69; SCEV does not know how to denormalize chained recurrences, so make 70; sure they aren't marked as post-inc users. 71; 72; CHECK-LABEL: IV Users for loop %test2.loop 73; CHECK-NO-LCSSA: %sub.cond.us = ((-1 * %sub.us)<nuw><nsw> + {0,+,1}<nuw><nsw><%test2.loop>) (post-inc with loop %test2.loop) in %sext.us = mul i32 %mul.us, %sub.cond.us 74define i32 @test2() { 75entry: 76 br label %test2.loop 77 78test2.loop: 79 %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ] 80 %inc11.us = add nsw i32 %inc1115.us, 1 81 %cmp.us = icmp slt i32 %inc11.us, 2 82 br i1 %cmp.us, label %test2.loop, label %for.end 83 84for.end: 85 %tobool.us = icmp eq i32 %inc1115.us, 0 86 %sub.us = select i1 %tobool.us, i32 0, i32 0 87 %mul.us = shl i32 %inc1115.us, 24 88 %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us 89 %sext.us = mul i32 %mul.us, %sub.cond.us 90 %f = ashr i32 %sext.us, 24 91 br label %exit 92 93exit: 94 ret i32 %f 95} 96