diff options
Diffstat (limited to 'test/Transforms/IndVarSimplify')
4 files changed, 185 insertions, 3 deletions
diff --git a/test/Transforms/IndVarSimplify/canonicalize-cmp.ll b/test/Transforms/IndVarSimplify/canonicalize-cmp.ll new file mode 100644 index 0000000000000..2b939767284a4 --- /dev/null +++ b/test/Transforms/IndVarSimplify/canonicalize-cmp.ll @@ -0,0 +1,98 @@ +; RUN: opt -S -indvars < %s | FileCheck %s + +; Check that we replace signed comparisons between non-negative values with +; unsigned comparisons if we can. + +target datalayout = "n8:16:32:64" + +define i32 @test_01(i32 %a, i32 %b, i32* %p) { + +; CHECK-LABEL: @test_01( +; CHECK-NOT: icmp slt +; CHECK: %cmp1 = icmp ult i32 %iv, 100 +; CHECK: %cmp2 = icmp ult i32 %iv, 100 +; CHECK-NOT: %cmp3 +; CHECK: %exitcond = icmp ne i32 %iv.next, 1000 + +entry: + br label %loop.entry + +loop.entry: + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ] + %cmp1 = icmp slt i32 %iv, 100 + br i1 %cmp1, label %b1, label %b2 + +b1: + store i32 %iv, i32* %p + br label %merge + +b2: + store i32 %a, i32* %p + br label %merge + +merge: + %cmp2 = icmp ult i32 %iv, 100 + br i1 %cmp2, label %b3, label %b4 + +b3: + store i32 %iv, i32* %p + br label %loop.be + +b4: + store i32 %b, i32* %p + br label %loop.be + +loop.be: + %iv.next = add i32 %iv, 1 + %cmp3 = icmp slt i32 %iv.next, 1000 + br i1 %cmp3, label %loop.entry, label %exit + +exit: + ret i32 %iv +} + +define i32 @test_02(i32 %a, i32 %b, i32* %p) { + +; CHECK-LABEL: @test_02( +; CHECK-NOT: icmp sgt +; CHECK: %cmp1 = icmp ugt i32 100, %iv +; CHECK: %cmp2 = icmp ugt i32 100, %iv +; CHECK-NOT: %cmp3 +; CHECK: %exitcond = icmp ne i32 %iv.next, 1000 + +entry: + br label %loop.entry + +loop.entry: + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ] + %cmp1 = icmp sgt i32 100, %iv + br i1 %cmp1, label %b1, label %b2 + +b1: + store i32 %iv, i32* %p + br label %merge + +b2: + store i32 %a, i32* %p + br label %merge + +merge: + %cmp2 = icmp ugt i32 100, %iv + br i1 %cmp2, label %b3, label %b4 + +b3: + store i32 %iv, i32* %p + br label %loop.be + +b4: + store i32 %b, i32* %p + br label %loop.be + +loop.be: + %iv.next = add i32 %iv, 1 + %cmp3 = icmp sgt i32 1000, %iv.next + br i1 %cmp3, label %loop.entry, label %exit + +exit: + ret i32 %iv +} diff --git a/test/Transforms/IndVarSimplify/eliminate-comparison.ll b/test/Transforms/IndVarSimplify/eliminate-comparison.ll index 612f01e3cadee..a63617e62c0ea 100644 --- a/test/Transforms/IndVarSimplify/eliminate-comparison.ll +++ b/test/Transforms/IndVarSimplify/eliminate-comparison.ll @@ -111,7 +111,7 @@ return: ; Indvars should not turn the second loop into an infinite one. ; CHECK-LABEL: @func_11( -; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10 +; CHECK: %tmp5 = icmp ult i32 %__key6.0, 10 ; CHECK-NOT: br i1 true, label %noassert68, label %unrolledend define i32 @func_11() nounwind uwtable { @@ -163,7 +163,7 @@ declare void @llvm.trap() noreturn nounwind ; In this case the second loop only has a single iteration, fold the header away ; CHECK-LABEL: @func_12( -; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10 +; CHECK: %tmp5 = icmp ult i32 %__key6.0, 10 ; CHECK: br i1 true, label %noassert68, label %unrolledend define i32 @func_12() nounwind uwtable { entry: diff --git a/test/Transforms/IndVarSimplify/strengthen-overflow.ll b/test/Transforms/IndVarSimplify/strengthen-overflow.ll index 2bafe96e1cccd..6e0538e04d6bd 100644 --- a/test/Transforms/IndVarSimplify/strengthen-overflow.ll +++ b/test/Transforms/IndVarSimplify/strengthen-overflow.ll @@ -104,5 +104,89 @@ define i32 @test.unsigned.add.1(i32* %array, i32 %length, i32 %init) { ret i32 42 } +define hidden void @test.shl.exact.equal() { +; CHECK-LABEL: @test.shl.exact.equal +entry: + br label %for.body + +for.body: +; CHECK-LABEL: for.body + %k.021 = phi i32 [ 1, %entry ], [ %inc, %for.body ] + %shl = shl i32 1, %k.021 + %shr1 = ashr i32 %shl, 1 +; CHECK: %shr1 = ashr exact i32 %shl, 1 + %shr2 = lshr i32 %shl, 1 +; CHECK: %shr2 = lshr exact i32 %shl, 1 + %inc = add nuw nsw i32 %k.021, 1 + %exitcond = icmp eq i32 %inc, 9 + br i1 %exitcond, label %for.end, label %for.body + +for.end: + ret void +} + +define hidden void @test.shl.exact.greater() { +; CHECK-LABEL: @test.shl.exact.greater +entry: + br label %for.body + +for.body: +; CHECK-LABEL: for.body + %k.021 = phi i32 [ 3, %entry ], [ %inc, %for.body ] + %shl = shl i32 1, %k.021 + %shr1 = ashr i32 %shl, 2 +; CHECK: %shr1 = ashr exact i32 %shl, 2 + %shr2 = lshr i32 %shl, 2 +; CHECK: %shr2 = lshr exact i32 %shl, 2 + %inc = add nuw nsw i32 %k.021, 1 + %exitcond = icmp eq i32 %inc, 9 + br i1 %exitcond, label %for.end, label %for.body + +for.end: + ret void +} + +define hidden void @test.shl.exact.unbound(i32 %arg) { +; CHECK-LABEL: @test.shl.exact.unbound +entry: + br label %for.body + +for.body: +; CHECK-LABEL: for.body + %k.021 = phi i32 [ 2, %entry ], [ %inc, %for.body ] + %shl = shl i32 1, %k.021 + %shr1 = ashr i32 %shl, 2 +; CHECK: %shr1 = ashr exact i32 %shl, 2 + %shr2 = lshr i32 %shl, 2 +; CHECK: %shr2 = lshr exact i32 %shl, 2 + %inc = add nuw nsw i32 %k.021, 1 + %exitcond = icmp eq i32 %inc, %arg + br i1 %exitcond, label %for.end, label %for.body + +for.end: + ret void +} + +define hidden void @test.shl.nonexact() { +; CHECK-LABEL: @test.shl.nonexact +entry: + br label %for.body + +for.body: +; CHECK-LABEL: for.body + %k.021 = phi i32 [ 2, %entry ], [ %inc, %for.body ] + %shl = shl i32 1, %k.021 + %shr1 = ashr i32 %shl, 3 +; CHECK: %shr1 = ashr i32 %shl, 3 + %shr2 = lshr i32 %shl, 3 +; CHECK: %shr2 = lshr i32 %shl, 3 + %inc = add nuw nsw i32 %k.021, 1 + %exitcond = icmp eq i32 %inc, 9 + br i1 %exitcond, label %for.end, label %for.body + +for.end: + ret void +} + !0 = !{i32 0, i32 2} !1 = !{i32 0, i32 42} diff --git a/test/Transforms/IndVarSimplify/widen-loop-comp.ll b/test/Transforms/IndVarSimplify/widen-loop-comp.ll index b87cd0550192e..2d24cd732ce84 100644 --- a/test/Transforms/IndVarSimplify/widen-loop-comp.ll +++ b/test/Transforms/IndVarSimplify/widen-loop-comp.ll @@ -64,7 +64,7 @@ for.end: ; CHECK-LABEL: @test2 ; CHECK: for.body4.us ; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 -; CHECK: %cmp2.us = icmp slt i64 +; CHECK: %cmp2.us = icmp ult i64 ; CHECK-NOT: %2 = trunc i64 %indvars.iv.next to i32 ; CHECK-NOT: %cmp2.us = icmp slt i32 |