From: Sanjay Patel Date: Fri, 25 Mar 2016 20:12:25 +0000 (+0000) Subject: [InstSimplify] regenerate checks using a script X-Git-Tag: llvmorg-3.9.0-rc1~10869 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69632447b198448376d779de1ca790b4445c55cc;p=platform%2Fupstream%2Fllvm.git [InstSimplify] regenerate checks using a script I didn't notice any significant changes in the actual checks here; all of these tests already used FileCheck, so a script can batch update them in one shot. This commit is just to show the value of automating this process: We have uniform formatting as opposed to a mish-mash of check structure that changes based on individual prefs and the current fashion. This makes it simpler to update when we find a bug or make an enhancement. llvm-svn: 264457 --- diff --git a/llvm/test/Transforms/InstSimplify/2010-12-20-Boolean.ll b/llvm/test/Transforms/InstSimplify/2010-12-20-Boolean.ll index 28c25c0..33f2176f 100644 --- a/llvm/test/Transforms/InstSimplify/2010-12-20-Boolean.ll +++ b/llvm/test/Transforms/InstSimplify/2010-12-20-Boolean.ll @@ -1,29 +1,34 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s define i1 @add(i1 %x) { ; CHECK-LABEL: @add( +; CHECK: ret i1 false +; %z = add i1 %x, %x ret i1 %z -; CHECK: ret i1 false } define i1 @sub(i1 %x) { ; CHECK-LABEL: @sub( +; CHECK: ret i1 %x +; %z = sub i1 false, %x ret i1 %z -; CHECK: ret i1 %x } define i1 @mul(i1 %x) { ; CHECK-LABEL: @mul( +; CHECK: ret i1 %x +; %z = mul i1 %x, %x ret i1 %z -; CHECK: ret i1 %x } define i1 @ne(i1 %x) { ; CHECK-LABEL: @ne( +; CHECK: ret i1 %x +; %z = icmp ne i1 %x, 0 ret i1 %z -; CHECK: ret i1 %x } diff --git a/llvm/test/Transforms/InstSimplify/AndOrXor.ll b/llvm/test/Transforms/InstSimplify/AndOrXor.ll index ce3c2aa..11f2524 100644 --- a/llvm/test/Transforms/InstSimplify/AndOrXor.ll +++ b/llvm/test/Transforms/InstSimplify/AndOrXor.ll @@ -1,205 +1,233 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s define i64 @pow2(i32 %x) { ; CHECK-LABEL: @pow2( +; CHECK: [[NEGX:%.*]] = sub i32 0, %x +; CHECK-NEXT: [[X2:%.*]] = and i32 %x, [[NEGX]] +; CHECK-NEXT: [[E:%.*]] = zext i32 [[X2]] to i64 +; CHECK-NEXT: ret i64 [[E]] +; %negx = sub i32 0, %x %x2 = and i32 %x, %negx %e = zext i32 %x2 to i64 %nege = sub i64 0, %e %e2 = and i64 %e, %nege ret i64 %e2 -; CHECK: ret i64 %e } define i64 @pow2b(i32 %x) { ; CHECK-LABEL: @pow2b( +; CHECK: [[SH:%.*]] = shl i32 2, %x +; CHECK-NEXT: [[E:%.*]] = zext i32 [[SH]] to i64 +; CHECK-NEXT: ret i64 [[E]] +; %sh = shl i32 2, %x %e = zext i32 %sh to i64 %nege = sub i64 0, %e %e2 = and i64 %e, %nege ret i64 %e2 -; CHECK: ret i64 %e } define i32 @sub_neg_nuw(i32 %x, i32 %y) { ; CHECK-LABEL: @sub_neg_nuw( +; CHECK: ret i32 %x +; %neg = sub nuw i32 0, %y %sub = sub i32 %x, %neg ret i32 %sub -; CHECK: ret i32 %x } define i1 @and_of_icmps0(i32 %b) { ; CHECK-LABEL: @and_of_icmps0( +; CHECK: ret i1 false +; %1 = add i32 %b, 2 %2 = icmp ult i32 %1, 4 %cmp3 = icmp sgt i32 %b, 2 %cmp = and i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 false } define i1 @and_of_icmps1(i32 %b) { ; CHECK-LABEL: @and_of_icmps1( +; CHECK: ret i1 false +; %1 = add nsw i32 %b, 2 %2 = icmp slt i32 %1, 4 %cmp3 = icmp sgt i32 %b, 2 %cmp = and i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 false } define i1 @and_of_icmps2(i32 %b) { ; CHECK-LABEL: @and_of_icmps2( +; CHECK: ret i1 false +; %1 = add i32 %b, 2 %2 = icmp ule i32 %1, 3 %cmp3 = icmp sgt i32 %b, 2 %cmp = and i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 false } define i1 @and_of_icmps3(i32 %b) { ; CHECK-LABEL: @and_of_icmps3( +; CHECK: ret i1 false +; %1 = add nsw i32 %b, 2 %2 = icmp sle i32 %1, 3 %cmp3 = icmp sgt i32 %b, 2 %cmp = and i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 false } define i1 @and_of_icmps4(i32 %b) { ; CHECK-LABEL: @and_of_icmps4( +; CHECK: ret i1 false +; %1 = add nuw i32 %b, 2 %2 = icmp ult i32 %1, 4 %cmp3 = icmp ugt i32 %b, 2 %cmp = and i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 false } define i1 @and_of_icmps5(i32 %b) { ; CHECK-LABEL: @and_of_icmps5( +; CHECK: ret i1 false +; %1 = add nuw i32 %b, 2 %2 = icmp ule i32 %1, 3 %cmp3 = icmp ugt i32 %b, 2 %cmp = and i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 false } define i1 @or_of_icmps0(i32 %b) { ; CHECK-LABEL: @or_of_icmps0( +; CHECK: ret i1 true +; %1 = add i32 %b, 2 %2 = icmp uge i32 %1, 4 %cmp3 = icmp sle i32 %b, 2 %cmp = or i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 true } define i1 @or_of_icmps1(i32 %b) { ; CHECK-LABEL: @or_of_icmps1( +; CHECK: ret i1 true +; %1 = add nsw i32 %b, 2 %2 = icmp sge i32 %1, 4 %cmp3 = icmp sle i32 %b, 2 %cmp = or i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 true } define i1 @or_of_icmps2(i32 %b) { ; CHECK-LABEL: @or_of_icmps2( +; CHECK: ret i1 true +; %1 = add i32 %b, 2 %2 = icmp ugt i32 %1, 3 %cmp3 = icmp sle i32 %b, 2 %cmp = or i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 true } define i1 @or_of_icmps3(i32 %b) { ; CHECK-LABEL: @or_of_icmps3( +; CHECK: ret i1 true +; %1 = add nsw i32 %b, 2 %2 = icmp sgt i32 %1, 3 %cmp3 = icmp sle i32 %b, 2 %cmp = or i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 true } define i1 @or_of_icmps4(i32 %b) { ; CHECK-LABEL: @or_of_icmps4( +; CHECK: ret i1 true +; %1 = add nuw i32 %b, 2 %2 = icmp uge i32 %1, 4 %cmp3 = icmp ule i32 %b, 2 %cmp = or i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 true } define i1 @or_of_icmps5(i32 %b) { ; CHECK-LABEL: @or_of_icmps5( +; CHECK: ret i1 true +; %1 = add nuw i32 %b, 2 %2 = icmp ugt i32 %1, 3 %cmp3 = icmp ule i32 %b, 2 %cmp = or i1 %2, %cmp3 ret i1 %cmp -; CHECK: ret i1 true } define i32 @neg_nuw(i32 %x) { ; CHECK-LABEL: @neg_nuw( +; CHECK: ret i32 0 +; %neg = sub nuw i32 0, %x ret i32 %neg -; CHECK: ret i32 0 } define i1 @and_icmp1(i32 %x, i32 %y) { +; CHECK-LABEL: @and_icmp1( +; CHECK: [[TMP1:%.*]] = icmp ult i32 %x, %y +; CHECK-NEXT: ret i1 [[TMP1]] +; %1 = icmp ult i32 %x, %y %2 = icmp ne i32 %y, 0 %3 = and i1 %1, %2 ret i1 %3 } -; CHECK-LABEL: @and_icmp1( -; CHECK: %[[cmp:.*]] = icmp ult i32 %x, %y -; CHECK: ret i1 %[[cmp]] define i1 @and_icmp2(i32 %x, i32 %y) { +; CHECK-LABEL: @and_icmp2( +; CHECK: ret i1 false +; %1 = icmp ult i32 %x, %y %2 = icmp eq i32 %y, 0 %3 = and i1 %1, %2 ret i1 %3 } -; CHECK-LABEL: @and_icmp2( -; CHECK: ret i1 false define i1 @or_icmp1(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp1( +; CHECK: [[TMP1:%.*]] = icmp ne i32 %y, 0 +; CHECK-NEXT: ret i1 [[TMP1]] +; %1 = icmp ult i32 %x, %y %2 = icmp ne i32 %y, 0 %3 = or i1 %1, %2 ret i1 %3 } -; CHECK-LABEL: @or_icmp1( -; CHECK: %[[cmp:.*]] = icmp ne i32 %y, 0 -; CHECK: ret i1 %[[cmp]] define i1 @or_icmp2(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp2( +; CHECK: ret i1 true +; %1 = icmp uge i32 %x, %y %2 = icmp ne i32 %y, 0 %3 = or i1 %1, %2 ret i1 %3 } -; CHECK-LABEL: @or_icmp2( -; CHECK: ret i1 true define i1 @or_icmp3(i32 %x, i32 %y) { +; CHECK-LABEL: @or_icmp3( +; CHECK: [[TMP1:%.*]] = icmp uge i32 %x, %y +; CHECK-NEXT: ret i1 [[TMP1]] +; %1 = icmp uge i32 %x, %y %2 = icmp eq i32 %y, 0 %3 = or i1 %1, %2 ret i1 %3 } -; CHECK-LABEL: @or_icmp3( -; CHECK: %[[cmp:.*]] = icmp uge i32 %x, %y -; CHECK: ret i1 %[[cmp]] + diff --git a/llvm/test/Transforms/InstSimplify/add-mask.ll b/llvm/test/Transforms/InstSimplify/add-mask.ll index 1e53cc5..e30a35f 100644 --- a/llvm/test/Transforms/InstSimplify/add-mask.ll +++ b/llvm/test/Transforms/InstSimplify/add-mask.ll @@ -1,8 +1,10 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt -S -instsimplify < %s | FileCheck %s define i1 @test(i32 %a) { -; CHECK-LABEL: @test -; CHECK: ret i1 false +; CHECK-LABEL: @test( +; CHECK: ret i1 false +; %rhs = add i32 %a, -1 %and = and i32 %a, %rhs %res = icmp eq i32 %and, 1 @@ -10,8 +12,9 @@ define i1 @test(i32 %a) { } define i1 @test2(i32 %a) { -; CHECK-LABEL: @test2 -; CHECK: ret i1 false +; CHECK-LABEL: @test2( +; CHECK: ret i1 false +; %rhs = add i32 %a, 1 %and = and i32 %a, %rhs %res = icmp eq i32 %and, 1 @@ -19,8 +22,9 @@ define i1 @test2(i32 %a) { } define i1 @test3(i32 %a) { -; CHECK-LABEL: @test3 -; CHECK: ret i1 false +; CHECK-LABEL: @test3( +; CHECK: ret i1 false +; %rhs = add i32 %a, 7 %and = and i32 %a, %rhs %res = icmp eq i32 %and, 1 @@ -32,8 +36,13 @@ declare void @llvm.assume(i1) ; Known bits without a constant define i1 @test4(i32 %a) { -; CHECK-LABEL: @test4 -; CHECK: ret i1 false +; CHECK-LABEL: @test4( +; CHECK: [[B:%.*]] = load i32, i32* @B +; CHECK-NEXT: [[B_AND:%.*]] = and i32 [[B]], 1 +; CHECK-NEXT: [[B_CND:%.*]] = icmp eq i32 [[B_AND]], 1 +; CHECK-NEXT: call void @llvm.assume(i1 [[B_CND]]) +; CHECK-NEXT: ret i1 false +; %b = load i32, i32* @B %b.and = and i32 %b, 1 %b.cnd = icmp eq i32 %b.and, 1 @@ -47,8 +56,12 @@ define i1 @test4(i32 %a) { ; Negative test - even number define i1 @test5(i32 %a) { -; CHECK-LABEL: @test5 -; CHECK: ret i1 %res +; CHECK-LABEL: @test5( +; CHECK: [[RHS:%.*]] = add i32 %a, 2 +; CHECK-NEXT: [[AND:%.*]] = and i32 %a, [[RHS]] +; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[AND]], 1 +; CHECK-NEXT: ret i1 [[RES]] +; %rhs = add i32 %a, 2 %and = and i32 %a, %rhs %res = icmp eq i32 %and, 1 @@ -56,8 +69,9 @@ define i1 @test5(i32 %a) { } define i1 @test6(i32 %a) { -; CHECK-LABEL: @test6 -; CHECK: ret i1 false +; CHECK-LABEL: @test6( +; CHECK: ret i1 false +; %lhs = add i32 %a, -1 %and = and i32 %lhs, %a %res = icmp eq i32 %and, 1 diff --git a/llvm/test/Transforms/InstSimplify/apint-or.ll b/llvm/test/Transforms/InstSimplify/apint-or.ll index 3684428..e3dc2c4 100644 --- a/llvm/test/Transforms/InstSimplify/apint-or.ll +++ b/llvm/test/Transforms/InstSimplify/apint-or.ll @@ -1,7 +1,13 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s ; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. define i39 @test1(i39 %V, i39 %M) { +; CHECK-LABEL: @test1( +; CHECK: [[N:%.*]] = and i39 %M, -274877906944 +; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]] +; CHECK-NEXT: ret i39 [[A]] +; ;; If we have: ((V + N) & C1) | (V & C2) ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 ;; replace with V+N. @@ -12,28 +18,31 @@ define i39 @test1(i39 %V, i39 %M) { %D = and i39 %V, 274877906943 %R = or i39 %B, %D ret i39 %R -; CHECK-LABEL: @test1 -; CHECK-NEXT: and {{.*}}, -274877906944 -; CHECK-NEXT: add -; CHECK-NEXT: ret } define i7 @test2(i7 %X) { +; CHECK-LABEL: @test2( +; CHECK: ret i7 %X +; %Y = or i7 %X, 0 ret i7 %Y -; CHECK-LABEL: @test2 -; CHECK-NEXT: ret i7 %X } define i17 @test3(i17 %X) { +; CHECK-LABEL: @test3( +; CHECK: ret i17 -1 +; %Y = or i17 %X, -1 ret i17 %Y -; CHECK-LABEL: @test3 -; CHECK-NEXT: ret i17 -1 } -; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. +; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. define i399 @test4(i399 %V, i399 %M) { +; CHECK-LABEL: @test4( +; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840 +; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]] +; CHECK-NEXT: ret i399 [[A]] +; ;; If we have: ((V + N) & C1) | (V & C2) ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 ;; replace with V+N. @@ -44,22 +53,20 @@ define i399 @test4(i399 %V, i399 %M) { %D = and i399 %V, 274877906943 %R = or i399 %B, %D ret i399 %R -; CHECK-LABEL: @test4 -; CHECK-NEXT: and {{.*}}, 18446742974197923840 -; CHECK-NEXT: add -; CHECK-NEXT: ret } define i777 @test5(i777 %X) { +; CHECK-LABEL: @test5( +; CHECK: ret i777 %X +; %Y = or i777 %X, 0 ret i777 %Y -; CHECK-LABEL: @test5 -; CHECK-NEXT: ret i777 %X } define i117 @test6(i117 %X) { +; CHECK-LABEL: @test6( +; CHECK: ret i117 -1 +; %Y = or i117 %X, -1 ret i117 %Y -; CHECK-LABEL: @test6 -; CHECK-NEXT: ret i117 -1 } diff --git a/llvm/test/Transforms/InstSimplify/assume.ll b/llvm/test/Transforms/InstSimplify/assume.ll index 4dd0a8f..2487a9c 100644 --- a/llvm/test/Transforms/InstSimplify/assume.ll +++ b/llvm/test/Transforms/InstSimplify/assume.ll @@ -1,12 +1,13 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt -instsimplify -S < %s | FileCheck %s define void @test1() { +; CHECK-LABEL: @test1( +; CHECK: ret void +; call void @llvm.assume(i1 1) ret void -; CHECK-LABEL: @test1 -; CHECK-NOT: llvm.assume -; CHECK: ret void } declare void @llvm.assume(i1) nounwind diff --git a/llvm/test/Transforms/InstSimplify/bswap.ll b/llvm/test/Transforms/InstSimplify/bswap.ll index 7bc3af9..5c67aa0 100644 --- a/llvm/test/Transforms/InstSimplify/bswap.ll +++ b/llvm/test/Transforms/InstSimplify/bswap.ll @@ -1,10 +1,12 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -S -instsimplify | FileCheck %s declare i16 @llvm.bswap.i16(i16) define i1 @test1(i16 %arg) { -; CHECK-LABEL: @test1 -; CHECK: ret i1 false +; CHECK-LABEL: @test1( +; CHECK: ret i1 false +; %a = or i16 %arg, 1 %b = call i16 @llvm.bswap.i16(i16 %a) %res = icmp eq i16 %b, 0 @@ -12,8 +14,9 @@ define i1 @test1(i16 %arg) { } define i1 @test2(i16 %arg) { -; CHECK-LABEL: @test2 -; CHECK: ret i1 false +; CHECK-LABEL: @test2( +; CHECK: ret i1 false +; %a = or i16 %arg, 1024 %b = call i16 @llvm.bswap.i16(i16 %a) %res = icmp eq i16 %b, 0 @@ -21,8 +24,9 @@ define i1 @test2(i16 %arg) { } define i1 @test3(i16 %arg) { -; CHECK-LABEL: @test3 -; CHECK: ret i1 false +; CHECK-LABEL: @test3( +; CHECK: ret i1 false +; %a = and i16 %arg, 1 %b = call i16 @llvm.bswap.i16(i16 %a) %and = and i16 %b, 1 @@ -31,8 +35,9 @@ define i1 @test3(i16 %arg) { } define i1 @test4(i16 %arg) { -; CHECK-LABEL: @test4 -; CHECK: ret i1 false +; CHECK-LABEL: @test4( +; CHECK: ret i1 false +; %a = and i16 %arg, 511 %b = call i16 @llvm.bswap.i16(i16 %a) %and = and i16 %b, 256 diff --git a/llvm/test/Transforms/InstSimplify/fast-math.ll b/llvm/test/Transforms/InstSimplify/fast-math.ll index c499af3..f4f3123 100644 --- a/llvm/test/Transforms/InstSimplify/fast-math.ll +++ b/llvm/test/Transforms/InstSimplify/fast-math.ll @@ -1,44 +1,60 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s ;; x * 0 ==> 0 when no-nans and no-signed-zero -; CHECK: mul_zero_1 define float @mul_zero_1(float %a) { +; CHECK-LABEL: @mul_zero_1( +; CHECK: ret float 0.000000e+00 +; %b = fmul nsz nnan float %a, 0.0 -; CHECK: ret float 0.0 ret float %b } -; CHECK: mul_zero_2 + define float @mul_zero_2(float %a) { +; CHECK-LABEL: @mul_zero_2( +; CHECK: ret float 0.000000e+00 +; %b = fmul fast float 0.0, %a -; CHECK: ret float 0.0 ret float %b } ;; x * 0 =/=> 0 when there could be nans or -0 -; CHECK: no_mul_zero_1 define float @no_mul_zero_1(float %a) { +; CHECK-LABEL: @no_mul_zero_1( +; CHECK: [[B:%.*]] = fmul nsz float %a, 0.000000e+00 +; CHECK-NEXT: ret float [[B]] +; %b = fmul nsz float %a, 0.0 -; CHECK: ret float %b ret float %b } -; CHECK: no_mul_zero_2 + define float @no_mul_zero_2(float %a) { +; CHECK-LABEL: @no_mul_zero_2( +; CHECK: [[B:%.*]] = fmul nnan float %a, 0.000000e+00 +; CHECK-NEXT: ret float [[B]] +; %b = fmul nnan float %a, 0.0 -; CHECK: ret float %b ret float %b } -; CHECK: no_mul_zero_3 + define float @no_mul_zero_3(float %a) { +; CHECK-LABEL: @no_mul_zero_3( +; CHECK: [[B:%.*]] = fmul float %a, 0.000000e+00 +; CHECK-NEXT: ret float [[B]] +; %b = fmul float %a, 0.0 -; CHECK: ret float %b ret float %b } ; fadd [nnan ninf] X, (fsub [nnan ninf] 0, X) ==> 0 ; where nnan and ninf have to occur at least once somewhere in this ; expression -; CHECK: fadd_fsub_0 define float @fadd_fsub_0(float %a) { +; CHECK-LABEL: @fadd_fsub_0( +; CHECK: [[NOFOLD:%.*]] = fsub float 0.000000e+00, %a +; CHECK-NEXT: [[NO_ZERO:%.*]] = fadd nnan float [[NOFOLD]], %a +; CHECK-NEXT: ret float [[NO_ZERO]] +; ; X + -X ==> 0 %t1 = fsub nnan ninf float 0.0, %a %zero1 = fadd nnan ninf float %t1, %a @@ -53,9 +69,7 @@ define float @fadd_fsub_0(float %a) { %zero4 = fadd nnan ninf float %t4, %a ; Dont fold this -; CHECK: %nofold = fsub float 0.0 %nofold = fsub float 0.0, %a -; CHECK: %no_zero = fadd nnan float %nofold, %a %no_zero = fadd nnan float %nofold, %a ; Coalesce the folded zeros @@ -66,118 +80,126 @@ define float @fadd_fsub_0(float %a) { ; Should get folded %ret = fadd nsz float %no_zero, %zero7 -; CHECK: ret float %no_zero ret float %ret } ; fsub nnan x, x ==> 0.0 -; CHECK-LABEL: @fsub_x_x( define float @fsub_x_x(float %a) { +; CHECK-LABEL: @fsub_x_x( +; CHECK: [[NO_ZERO1:%.*]] = fsub ninf float %a, %a +; CHECK-NEXT: [[NO_ZERO2:%.*]] = fsub float %a, %a +; CHECK-NEXT: [[NO_ZERO:%.*]] = fadd float [[NO_ZERO1:%.*]], [[NO_ZERO2:%.*]] +; CHECK-NEXT: ret float [[NO_ZERO]] +; ; X - X ==> 0 %zero1 = fsub nnan float %a, %a ; Dont fold -; CHECK: %no_zero1 = fsub %no_zero1 = fsub ninf float %a, %a -; CHECK: %no_zero2 = fsub %no_zero2 = fsub float %a, %a -; CHECK: %no_zero = fadd %no_zero = fadd float %no_zero1, %no_zero2 ; Should get folded %ret = fadd nsz float %no_zero, %zero1 -; CHECK: ret float %no_zero ret float %ret } ; fsub nsz 0.0, (fsub 0.0, X) ==> X -; CHECK-LABEL: @fsub_0_0_x( define float @fsub_0_0_x(float %a) { +; CHECK-LABEL: @fsub_0_0_x( +; CHECK: ret float %a +; %t1 = fsub float 0.0, %a %ret = fsub nsz float 0.0, %t1 - -; CHECK: ret float %a ret float %ret } ; fadd nsz X, 0 ==> X -; CHECK-LABEL: @nofold_fadd_x_0( define float @nofold_fadd_x_0(float %a) { +; CHECK-LABEL: @nofold_fadd_x_0( +; CHECK: [[NO_ZERO1:%.*]] = fadd ninf float %a, 0.000000e+00 +; CHECK-NEXT: [[NO_ZERO2:%.*]] = fadd nnan float %a, 0.000000e+00 +; CHECK-NEXT: [[NO_ZERO:%.*]] = fadd float [[NO_ZERO1:%.*]], [[NO_ZERO2:%.*]] +; CHECK-NEXT: ret float [[NO_ZERO]] +; ; Dont fold -; CHECK: %no_zero1 = fadd %no_zero1 = fadd ninf float %a, 0.0 -; CHECK: %no_zero2 = fadd %no_zero2 = fadd nnan float %a, 0.0 -; CHECK: %no_zero = fadd %no_zero = fadd float %no_zero1, %no_zero2 - -; CHECK: ret float %no_zero ret float %no_zero } ; fdiv nsz nnan 0, X ==> 0 define double @fdiv_zero_by_x(double %X) { ; CHECK-LABEL: @fdiv_zero_by_x( +; CHECK: ret double 0.000000e+00 +; ; 0 / X -> 0 %r = fdiv nnan nsz double 0.0, %X ret double %r -; CHECK: ret double 0 } define float @fdiv_self(float %f) { +; CHECK-LABEL: @fdiv_self( +; CHECK: ret float 1.000000e+00 +; %div = fdiv nnan float %f, %f ret float %div -; CHECK-LABEL: fdiv_self -; CHECK: ret float 1.000000e+00 } define float @fdiv_self_invalid(float %f) { +; CHECK-LABEL: @fdiv_self_invalid( +; CHECK: [[DIV:%.*]] = fdiv float %f, %f +; CHECK-NEXT: ret float [[DIV]] +; %div = fdiv float %f, %f ret float %div -; CHECK-LABEL: fdiv_self_invalid -; CHECK: %div = fdiv float %f, %f -; CHECK-NEXT: ret float %div } define float @fdiv_neg1(float %f) { +; CHECK-LABEL: @fdiv_neg1( +; CHECK: ret float -1.000000e+00 +; %neg = fsub fast float -0.000000e+00, %f %div = fdiv nnan float %neg, %f ret float %div -; CHECK-LABEL: fdiv_neg1 -; CHECK: ret float -1.000000e+00 } define float @fdiv_neg2(float %f) { +; CHECK-LABEL: @fdiv_neg2( +; CHECK: ret float -1.000000e+00 +; %neg = fsub fast float 0.000000e+00, %f %div = fdiv nnan float %neg, %f ret float %div -; CHECK-LABEL: fdiv_neg2 -; CHECK: ret float -1.000000e+00 } define float @fdiv_neg_invalid(float %f) { +; CHECK-LABEL: @fdiv_neg_invalid( +; CHECK: [[NEG:%.*]] = fsub fast float -0.000000e+00, %f +; CHECK-NEXT: [[DIV:%.*]] = fdiv float [[NEG]], %f +; CHECK-NEXT: ret float [[DIV]] +; %neg = fsub fast float -0.000000e+00, %f %div = fdiv float %neg, %f ret float %div -; CHECK-LABEL: fdiv_neg_invalid -; CHECK: %neg = fsub fast float -0.000000e+00, %f -; CHECK-NEXT: %div = fdiv float %neg, %f -; CHECK-NEXT: ret float %div } define float @fdiv_neg_swapped1(float %f) { +; CHECK-LABEL: @fdiv_neg_swapped1( +; CHECK: ret float -1.000000e+00 +; %neg = fsub float -0.000000e+00, %f %div = fdiv nnan float %f, %neg ret float %div -; CHECK-LABEL: fdiv_neg_swapped1 -; CHECK: ret float -1.000000e+00 } define float @fdiv_neg_swapped2(float %f) { +; CHECK-LABEL: @fdiv_neg_swapped2( +; CHECK: ret float -1.000000e+00 +; %neg = fsub float 0.000000e+00, %f %div = fdiv nnan float %f, %neg ret float %div -; CHECK-LABEL: fdiv_neg_swapped2 -; CHECK: ret float -1.000000e+00 } diff --git a/llvm/test/Transforms/InstSimplify/fdiv.ll b/llvm/test/Transforms/InstSimplify/fdiv.ll index 53ad25d..bb7f443 100644 --- a/llvm/test/Transforms/InstSimplify/fdiv.ll +++ b/llvm/test/Transforms/InstSimplify/fdiv.ll @@ -1,17 +1,20 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s define double @fdiv_of_undef(double %X) { ; CHECK-LABEL: @fdiv_of_undef( +; CHECK: ret double undef +; ; undef / X -> undef %r = fdiv double undef, %X ret double %r -; CHECK: ret double undef } define double @fdiv_by_undef(double %X) { ; CHECK-LABEL: @fdiv_by_undef( +; CHECK: ret double undef +; ; X / undef -> undef %r = fdiv double %X, undef ret double %r -; CHECK: ret double undef } diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll index 1c29884..b825ac8 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll @@ -1,71 +1,83 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s ; fsub -0.0, (fsub -0.0, X) ==> X -; CHECK-LABEL: @fsub_-0_-0_x( define float @fsub_-0_-0_x(float %a) { +; CHECK-LABEL: @fsub_-0_-0_x( +; CHECK: ret float %a +; %t1 = fsub float -0.0, %a %ret = fsub float -0.0, %t1 - -; CHECK: ret float %a ret float %ret } ; fsub 0.0, (fsub -0.0, X) != X -; CHECK-LABEL: @fsub_0_-0_x( define float @fsub_0_-0_x(float %a) { +; CHECK-LABEL: @fsub_0_-0_x( +; CHECK: [[T1:%.*]] = fsub float 0.000000e+00, %a +; CHECK-NEXT: [[RET:%.*]] = fsub float -0.000000e+00, [[T1]] +; CHECK-NEXT: ret float [[RET]] +; %t1 = fsub float 0.0, %a %ret = fsub float -0.0, %t1 - -; CHECK-NOT: ret float %a ret float %ret } ; fsub -0.0, (fsub 0.0, X) != X -; CHECK-LABEL: @fsub_-0_0_x( define float @fsub_-0_0_x(float %a) { +; CHECK-LABEL: @fsub_-0_0_x( +; CHECK: [[T1:%.*]] = fsub float -0.000000e+00, %a +; CHECK-NEXT: [[RET:%.*]] = fsub float 0.000000e+00, [[T1]] +; CHECK-NEXT: ret float [[RET]] +; %t1 = fsub float -0.0, %a %ret = fsub float 0.0, %t1 - -; CHECK-NOT: ret float %a ret float %ret } ; fsub X, 0 ==> X -; CHECK-LABEL: @fsub_x_0( define float @fsub_x_0(float %a) { +; CHECK-LABEL: @fsub_x_0( +; CHECK: ret float %a +; %ret = fsub float %a, 0.0 -; CHECK: ret float %a ret float %ret } ; fadd X, -0 ==> X -; CHECK-LABEL: @fadd_x_n0( define float @fadd_x_n0(float %a) { +; CHECK-LABEL: @fadd_x_n0( +; CHECK: ret float %a +; %ret = fadd float %a, -0.0 -; CHECK: ret float %a ret float %ret } ; fmul X, 1.0 ==> X -; CHECK-LABEL: @fmul_X_1( define double @fmul_X_1(double %a) { - %b = fmul double 1.000000e+00, %a ; [#uses=1] - ; CHECK: ret double %a +; CHECK-LABEL: @fmul_X_1( +; CHECK: ret double %a +; + %b = fmul double 1.000000e+00, %a ret double %b } ; We can't optimize away the fadd in this test because the input -; value to the function and subsequently to the fadd may be -0.0. +; value to the function and subsequently to the fadd may be -0.0. ; In that one special case, the result of the fadd should be +0.0 ; rather than the first parameter of the fadd. -; Fragile test warning: We need 6 sqrt calls to trigger the bug -; because the internal logic has a magic recursion limit of 6. +; Fragile test warning: We need 6 sqrt calls to trigger the bug +; because the internal logic has a magic recursion limit of 6. ; This is presented without any explanation or ability to customize. declare float @sqrtf(float) define float @PR22688(float %x) { +; CHECK-LABEL: @PR22688( +; CHECK: [[TMP7:%.*]] = fadd float {{%.*}}, 0.000000e+00 +; CHECK-NEXT: ret float [[TMP7]] +; %1 = call float @sqrtf(float %x) %2 = call float @sqrtf(float %1) %3 = call float @sqrtf(float %2) @@ -74,8 +86,5 @@ define float @PR22688(float %x) { %6 = call float @sqrtf(float %5) %7 = fadd float %6, 0.0 ret float %7 - -; CHECK-LABEL: @PR22688( -; CHECK: fadd float %6, 0.0 } diff --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll index b148d99..7c67ffb 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll +++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll @@ -1,7 +1,8 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s ; These tests choose arbitrarily between float and double, -; and between uge and olt, to give reasonble coverage +; and between uge and olt, to give reasonble coverage ; without combinatorial explosion. declare float @llvm.fabs.f32(float) @@ -15,8 +16,10 @@ declare float @llvm.fma.f32(float,float,float) declare void @expect_equal(i1,i1) -; CHECK-LABEL: @orderedLessZeroTree( define i1 @orderedLessZeroTree(float,float,float,float) { +; CHECK-LABEL: @orderedLessZeroTree( +; CHECK: ret i1 true +; %square = fmul float %0, %0 %abs = call float @llvm.fabs.f32(float %1) %sqrt = call float @llvm.sqrt.f32(float %2) @@ -25,30 +28,33 @@ define i1 @orderedLessZeroTree(float,float,float,float) { %rem = frem float %sqrt, %fma %add = fadd float %div, %rem %uge = fcmp uge float %add, 0.000000e+00 -; CHECK: ret i1 true ret i1 %uge } -; CHECK-LABEL: @orderedLessZeroExpExt( define i1 @orderedLessZeroExpExt(float) { +; CHECK-LABEL: @orderedLessZeroExpExt( +; CHECK: ret i1 true +; %a = call float @llvm.exp.f32(float %0) %b = fpext float %a to double %uge = fcmp uge double %b, 0.000000e+00 -; CHECK: ret i1 true ret i1 %uge } -; CHECK-LABEL: @orderedLessZeroExp2Trunc( define i1 @orderedLessZeroExp2Trunc(double) { +; CHECK-LABEL: @orderedLessZeroExp2Trunc( +; CHECK: ret i1 false +; %a = call double @llvm.exp2.f64(double %0) %b = fptrunc double %a to float %olt = fcmp olt float %b, 0.000000e+00 -; CHECK: ret i1 false ret i1 %olt } -; CHECK-LABEL: @orderedLessZeroPowi( define i1 @orderedLessZeroPowi(double,double) { +; CHECK-LABEL: @orderedLessZeroPowi( +; CHECK: ret i1 false +; ; Even constant exponent %a = call double @llvm.powi.f64(double %0, i32 2) %square = fmul double %1, %1 @@ -56,61 +62,64 @@ define i1 @orderedLessZeroPowi(double,double) { %b = call double @llvm.powi.f64(double %square, i32 3) %c = fadd double %a, %b %olt = fcmp olt double %b, 0.000000e+00 -; CHECK: ret i1 false ret i1 %olt } -; CHECK-LABEL: @orderedLessZeroUIToFP( define i1 @orderedLessZeroUIToFP(i32) { +; CHECK-LABEL: @orderedLessZeroUIToFP( +; CHECK: ret i1 true +; %a = uitofp i32 %0 to float %uge = fcmp uge float %a, 0.000000e+00 -; CHECK: ret i1 true ret i1 %uge } -; CHECK-LABEL: @orderedLessZeroSelect( define i1 @orderedLessZeroSelect(float, float) { +; CHECK-LABEL: @orderedLessZeroSelect( +; CHECK: ret i1 true +; %a = call float @llvm.exp.f32(float %0) %b = call float @llvm.fabs.f32(float %1) %c = fcmp olt float %0, %1 %d = select i1 %c, float %a, float %b %e = fadd float %d, 1.0 %uge = fcmp uge float %e, 0.000000e+00 -; CHECK: ret i1 true ret i1 %uge } -; CHECK-LABEL: @orderedLessZeroMinNum( define i1 @orderedLessZeroMinNum(float, float) { +; CHECK-LABEL: @orderedLessZeroMinNum( +; CHECK: ret i1 true +; %a = call float @llvm.exp.f32(float %0) %b = call float @llvm.fabs.f32(float %1) %c = call float @llvm.minnum.f32(float %a, float %b) %uge = fcmp uge float %c, 0.000000e+00 -; CHECK: ret i1 true ret i1 %uge } -; CHECK-LABEL: @orderedLessZeroMaxNum( define i1 @orderedLessZeroMaxNum(float, float) { +; CHECK-LABEL: @orderedLessZeroMaxNum( +; CHECK: ret i1 true +; %a = call float @llvm.exp.f32(float %0) %b = call float @llvm.maxnum.f32(float %a, float %1) %uge = fcmp uge float %b, 0.000000e+00 -; CHECK: ret i1 true ret i1 %uge } define i1 @nonans1(double %in1, double %in2) { +; CHECK-LABEL: @nonans1( +; CHECK: ret i1 false +; %cmp = fcmp nnan uno double %in1, %in2 ret i1 %cmp - -; CHECK-LABEL: @nonans1 -; CHECK-NEXT: ret i1 false } define i1 @nonans2(double %in1, double %in2) { +; CHECK-LABEL: @nonans2( +; CHECK: ret i1 true +; %cmp = fcmp nnan ord double %in1, %in2 ret i1 %cmp - -; CHECK-LABEL: @nonans2 -; CHECK-NEXT: ret i1 true } diff --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll index 2e3c959..2375965 100644 --- a/llvm/test/Transforms/InstSimplify/implies.ll +++ b/llvm/test/Transforms/InstSimplify/implies.ll @@ -1,9 +1,11 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt -S %s -instsimplify | FileCheck %s ; A ==> A -> true define i1 @test(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test -; CHECK: ret i1 true +; CHECK-LABEL: @test( +; CHECK: ret i1 true +; %var29 = icmp slt i32 %i, %length.i %res = icmp uge i1 %var29, %var29 ret i1 %res @@ -11,8 +13,9 @@ define i1 @test(i32 %length.i, i32 %i) { ; i +_{nsw} C_{>0} i true define i1 @test2(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test2 -; CHECK: ret i1 true +; CHECK-LABEL: @test2( +; CHECK: ret i1 true +; %iplus1 = add nsw i32 %i, 1 %var29 = icmp slt i32 %i, %length.i %var30 = icmp slt i32 %iplus1, %length.i @@ -22,8 +25,13 @@ define i1 @test2(i32 %length.i, i32 %i) { ; i + C_{>0} i unknown without the nsw define i1 @test2_neg(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test2_neg -; CHECK: ret i1 %res +; CHECK-LABEL: @test2_neg( +; CHECK: [[IPLUS1:%.*]] = add i32 %i, 1 +; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 %i, %length.i +; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[IPLUS1]], %length.i +; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]] +; CHECK-NEXT: ret i1 [[RES]] +; %iplus1 = add i32 %i, 1 %var29 = icmp slt i32 %i, %length.i %var30 = icmp slt i32 %iplus1, %length.i @@ -33,8 +41,13 @@ define i1 @test2_neg(i32 %length.i, i32 %i) { ; sle is not implication define i1 @test2_neg2(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test2_neg2 -; CHECK: ret i1 %res +; CHECK-LABEL: @test2_neg2( +; CHECK: [[IPLUS1:%.*]] = add i32 %i, 1 +; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 %i, %length.i +; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[IPLUS1]], %length.i +; CHECK-NEXT: [[RES:%.*]] = icmp sle i1 [[VAR30]], [[VAR29]] +; CHECK-NEXT: ret i1 [[RES]] +; %iplus1 = add i32 %i, 1 %var29 = icmp slt i32 %i, %length.i %var30 = icmp slt i32 %iplus1, %length.i @@ -44,8 +57,13 @@ define i1 @test2_neg2(i32 %length.i, i32 %i) { ; The binary operator has to be an add define i1 @test2_neg3(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test2_neg3 -; CHECK: ret i1 %res +; CHECK-LABEL: @test2_neg3( +; CHECK: [[IPLUS1:%.*]] = sub nsw i32 %i, 1 +; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 %i, %length.i +; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[IPLUS1]], %length.i +; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]] +; CHECK-NEXT: ret i1 [[RES]] +; %iplus1 = sub nsw i32 %i, 1 %var29 = icmp slt i32 %i, %length.i %var30 = icmp slt i32 %iplus1, %length.i @@ -56,8 +74,9 @@ define i1 @test2_neg3(i32 %length.i, i32 %i) { ; i +_{nsw} C_{>0} i true ; With an inverted conditional (ule B A rather than canonical ugt A B define i1 @test3(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test3 -; CHECK: ret i1 true +; CHECK-LABEL: @test3( +; CHECK: ret i1 true +; %iplus1 = add nsw i32 %i, 1 %var29 = icmp slt i32 %i, %length.i %var30 = icmp slt i32 %iplus1, %length.i @@ -67,8 +86,9 @@ define i1 @test3(i32 %length.i, i32 %i) { ; i +_{nuw} C i A for vectors define <4 x i1> @test5(<4 x i1> %vec) { -; CHECK-LABEL: @test5 -; CHECK: ret <4 x i1> +; CHECK-LABEL: @test5( +; CHECK: ret <4 x i1> +; %res = icmp ule <4 x i1> %vec, %vec ret <4 x i1> %res } ; Don't crash on vector inputs - pr25040 define <4 x i1> @test6(<4 x i1> %a, <4 x i1> %b) { -; CHECK-LABEL: @test6 -; CHECK: ret <4 x i1> %res +; CHECK-LABEL: @test6( +; CHECK: [[RES:%.*]] = icmp ule <4 x i1> %a, %b +; CHECK-NEXT: ret <4 x i1> [[RES]] +; %res = icmp ule <4 x i1> %a, %b ret <4 x i1> %res } @@ -95,7 +118,8 @@ define <4 x i1> @test6(<4 x i1> %a, <4 x i1> %b) { ; i +_{nsw} 1 i < L +_{nsw} 1 define i1 @test7(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test7( -; CHECK: ret i1 true +; CHECK: ret i1 true +; %iplus1 = add nsw i32 %i, 1 %len.plus.one = add nsw i32 %length.i, 1 %var29 = icmp slt i32 %i, %len.plus.one @@ -107,7 +131,8 @@ define i1 @test7(i32 %length.i, i32 %i) { ; i +_{nuw} 1 i < L +_{nuw} 1 define i1 @test8(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test8( -; CHECK: ret i1 true +; CHECK: ret i1 true +; %iplus1 = add nuw i32 %i, 1 %len.plus.one = add nuw i32 %length.i, 1 %var29 = icmp ult i32 %i, %len.plus.one @@ -119,7 +144,8 @@ define i1 @test8(i32 %length.i, i32 %i) { ; i +_{nuw} C i < L, even if C is negative define i1 @test9(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test9( -; CHECK: ret i1 true +; CHECK: ret i1 true +; %iplus1 = add nuw i32 %i, -100 %var29 = icmp ult i32 %i, %length.i %var30 = icmp ult i32 %iplus1, %length.i @@ -129,8 +155,8 @@ define i1 @test9(i32 %length.i, i32 %i) { define i1 @test10(i32 %length.i, i32 %x.full) { ; CHECK-LABEL: @test10( -; CHECK: ret i1 true - +; CHECK: ret i1 true +; %x = and i32 %x.full, 4294901760 ;; 4294901760 == 0xffff0000 %large = or i32 %x, 100 %small = or i32 %x, 90 @@ -142,9 +168,13 @@ define i1 @test10(i32 %length.i, i32 %x.full) { define i1 @test11(i32 %length.i, i32 %x) { ; CHECK-LABEL: @test11( -; CHECK: %res = icmp ule i1 %known, %to.prove -; CHECK: ret i1 %res - +; CHECK: [[LARGE:%.*]] = or i32 %x, 100 +; CHECK-NEXT: [[SMALL:%.*]] = or i32 %x, 90 +; CHECK-NEXT: [[KNOWN:%.*]] = icmp ult i32 [[LARGE]], %length.i +; CHECK-NEXT: [[TO_PROVE:%.*]] = icmp ult i32 [[SMALL]], %length.i +; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[KNOWN]], [[TO_PROVE]] +; CHECK-NEXT: ret i1 [[RES]] +; %large = or i32 %x, 100 %small = or i32 %x, 90 %known = icmp ult i32 %large, %length.i @@ -155,9 +185,14 @@ define i1 @test11(i32 %length.i, i32 %x) { define i1 @test12(i32 %length.i, i32 %x.full) { ; CHECK-LABEL: @test12( -; CHECK: %res = icmp ule i1 %known, %to.prove -; CHECK: ret i1 %res - +; CHECK: [[X:%.*]] = and i32 [[X:%.*]].full, -65536 +; CHECK-NEXT: [[LARGE:%.*]] = or i32 [[X]], 65536 +; CHECK-NEXT: [[SMALL:%.*]] = or i32 [[X]], 90 +; CHECK-NEXT: [[KNOWN:%.*]] = icmp ult i32 [[LARGE]], %length.i +; CHECK-NEXT: [[TO_PROVE:%.*]] = icmp ult i32 [[SMALL]], %length.i +; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[KNOWN]], [[TO_PROVE]] +; CHECK-NEXT: ret i1 [[RES]] +; %x = and i32 %x.full, 4294901760 ;; 4294901760 == 0xffff0000 %large = or i32 %x, 65536 ;; 65536 == 0x00010000 %small = or i32 %x, 90 @@ -169,8 +204,8 @@ define i1 @test12(i32 %length.i, i32 %x.full) { define i1 @test13(i32 %length.i, i32 %x) { ; CHECK-LABEL: @test13( -; CHECK: ret i1 true - +; CHECK: ret i1 true +; %large = add nuw i32 %x, 100 %small = add nuw i32 %x, 90 %known = icmp ult i32 %large, %length.i @@ -181,8 +216,8 @@ define i1 @test13(i32 %length.i, i32 %x) { define i1 @test14(i32 %length.i, i32 %x.full) { ; CHECK-LABEL: @test14( -; CHECK: ret i1 true - +; CHECK: ret i1 true +; %x = and i32 %x.full, 4294905615 ;; 4294905615 == 0xffff0f0f %large = or i32 %x, 8224 ;; == 0x2020 %small = or i32 %x, 4112 ;; == 0x1010 @@ -194,9 +229,13 @@ define i1 @test14(i32 %length.i, i32 %x.full) { define i1 @test15(i32 %length.i, i32 %x) { ; CHECK-LABEL: @test15( -; CHECK: %res = icmp ule i1 %known, %to.prove -; CHECK: ret i1 %res - +; CHECK: [[LARGE:%.*]] = add nuw i32 %x, 100 +; CHECK-NEXT: [[SMALL:%.*]] = add nuw i32 %x, 110 +; CHECK-NEXT: [[KNOWN:%.*]] = icmp ult i32 [[LARGE]], %length.i +; CHECK-NEXT: [[TO_PROVE:%.*]] = icmp ult i32 [[SMALL]], %length.i +; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[KNOWN]], [[TO_PROVE]] +; CHECK-NEXT: ret i1 [[RES]] +; %large = add nuw i32 %x, 100 %small = add nuw i32 %x, 110 %known = icmp ult i32 %large, %length.i @@ -207,8 +246,9 @@ define i1 @test15(i32 %length.i, i32 %x) { ; X >=(s) Y == X ==> Y (i1 1 becomes -1 for reasoning) define i1 @test_sge(i32 %length.i, i32 %i) { -; CHECK-LABEL: @test_sge -; CHECK: ret i1 true +; CHECK-LABEL: @test_sge( +; CHECK: ret i1 true +; %iplus1 = add nsw nuw i32 %i, 1 %var29 = icmp ult i32 %i, %length.i %var30 = icmp ult i32 %iplus1, %length.i diff --git a/llvm/test/Transforms/InstSimplify/load.ll b/llvm/test/Transforms/InstSimplify/load.ll index ab87d4b..ba789df 100644 --- a/llvm/test/Transforms/InstSimplify/load.ll +++ b/llvm/test/Transforms/InstSimplify/load.ll @@ -1,18 +1,21 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s @zeroinit = constant {} zeroinitializer @undef = constant {} undef define i32 @crash_on_zeroinit() { -; CHECK-LABEL: @crash_on_zeroinit -; CHECK: ret i32 0 +; CHECK-LABEL: @crash_on_zeroinit( +; CHECK: ret i32 0 +; %load = load i32, i32* bitcast ({}* @zeroinit to i32*) ret i32 %load } define i32 @crash_on_undef() { -; CHECK-LABEL: @crash_on_undef -; CHECK: ret i32 undef +; CHECK-LABEL: @crash_on_undef( +; CHECK: ret i32 undef +; %load = load i32, i32* bitcast ({}* @undef to i32*) ret i32 %load } diff --git a/llvm/test/Transforms/InstSimplify/maxmin.ll b/llvm/test/Transforms/InstSimplify/maxmin.ll index 3c643ed..3fcbfec 100644 --- a/llvm/test/Transforms/InstSimplify/maxmin.ll +++ b/llvm/test/Transforms/InstSimplify/maxmin.ll @@ -1,269 +1,302 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s define i1 @max1(i32 %x, i32 %y) { ; CHECK-LABEL: @max1( +; CHECK: ret i1 false +; %c = icmp sgt i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp slt i32 %m, %x ret i1 %r -; CHECK: ret i1 false } define i1 @max2(i32 %x, i32 %y) { ; CHECK-LABEL: @max2( +; CHECK: ret i1 true +; %c = icmp sge i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp sge i32 %m, %x ret i1 %r -; CHECK: ret i1 true } define i1 @max3(i32 %x, i32 %y) { ; CHECK-LABEL: @max3( +; CHECK: ret i1 false +; %c = icmp ugt i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp ult i32 %m, %x ret i1 %r -; CHECK: ret i1 false } define i1 @max4(i32 %x, i32 %y) { ; CHECK-LABEL: @max4( +; CHECK: ret i1 true +; %c = icmp uge i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp uge i32 %m, %x ret i1 %r -; CHECK: ret i1 true } define i1 @max5(i32 %x, i32 %y) { ; CHECK-LABEL: @max5( +; CHECK: ret i1 false +; %c = icmp sgt i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp sgt i32 %x, %m ret i1 %r -; CHECK: ret i1 false } define i1 @max6(i32 %x, i32 %y) { ; CHECK-LABEL: @max6( +; CHECK: ret i1 true +; %c = icmp sge i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp sle i32 %x, %m ret i1 %r -; CHECK: ret i1 true } define i1 @max7(i32 %x, i32 %y) { ; CHECK-LABEL: @max7( +; CHECK: ret i1 false +; %c = icmp ugt i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp ugt i32 %x, %m ret i1 %r -; CHECK: ret i1 false } define i1 @max8(i32 %x, i32 %y) { ; CHECK-LABEL: @max8( +; CHECK: ret i1 true +; %c = icmp uge i32 %x, %y %m = select i1 %c, i32 %x, i32 %y %r = icmp ule i32 %x, %m ret i1 %r -; CHECK: ret i1 true } define i1 @min1(i32 %x, i32 %y) { ; CHECK-LABEL: @min1( +; CHECK: ret i1 false +; %c = icmp sgt i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp sgt i32 %m, %x ret i1 %r -; CHECK: ret i1 false } define i1 @min2(i32 %x, i32 %y) { ; CHECK-LABEL: @min2( +; CHECK: ret i1 true +; %c = icmp sge i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp sle i32 %m, %x ret i1 %r -; CHECK: ret i1 true } define i1 @min3(i32 %x, i32 %y) { ; CHECK-LABEL: @min3( +; CHECK: ret i1 false +; %c = icmp ugt i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp ugt i32 %m, %x ret i1 %r -; CHECK: ret i1 false } define i1 @min4(i32 %x, i32 %y) { ; CHECK-LABEL: @min4( +; CHECK: ret i1 true +; %c = icmp uge i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp ule i32 %m, %x ret i1 %r -; CHECK: ret i1 true } define i1 @min5(i32 %x, i32 %y) { ; CHECK-LABEL: @min5( +; CHECK: ret i1 false +; %c = icmp sgt i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp slt i32 %x, %m ret i1 %r -; CHECK: ret i1 false } define i1 @min6(i32 %x, i32 %y) { ; CHECK-LABEL: @min6( +; CHECK: ret i1 true +; %c = icmp sge i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp sge i32 %x, %m ret i1 %r -; CHECK: ret i1 true } define i1 @min7(i32 %x, i32 %y) { ; CHECK-LABEL: @min7( +; CHECK: ret i1 false +; %c = icmp ugt i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp ult i32 %x, %m ret i1 %r -; CHECK: ret i1 false } define i1 @min8(i32 %x, i32 %y) { ; CHECK-LABEL: @min8( +; CHECK: ret i1 true +; %c = icmp uge i32 %x, %y %m = select i1 %c, i32 %y, i32 %x %r = icmp uge i32 %x, %m ret i1 %r -; CHECK: ret i1 true } define i1 @maxmin1(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin1( +; CHECK: ret i1 true +; %c1 = icmp sge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp sge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp sge i32 %max, %min ret i1 %c -; CHECK: ret i1 true } define i1 @maxmin2(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin2( +; CHECK: ret i1 false +; %c1 = icmp sge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp sge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp sgt i32 %min, %max ret i1 %c -; CHECK: ret i1 false } define i1 @maxmin3(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin3( +; CHECK: ret i1 true +; %c1 = icmp sge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp sge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp sle i32 %min, %max ret i1 %c -; CHECK: ret i1 true } define i1 @maxmin4(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin4( +; CHECK: ret i1 false +; %c1 = icmp sge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp sge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp slt i32 %max, %min ret i1 %c -; CHECK: ret i1 false } define i1 @maxmin5(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin5( +; CHECK: ret i1 true +; %c1 = icmp uge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp uge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp uge i32 %max, %min ret i1 %c -; CHECK: ret i1 true } define i1 @maxmin6(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin6( +; CHECK: ret i1 false +; %c1 = icmp uge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp uge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp ugt i32 %min, %max ret i1 %c -; CHECK: ret i1 false } define i1 @maxmin7(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin7( +; CHECK: ret i1 true +; %c1 = icmp uge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp uge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp ule i32 %min, %max ret i1 %c -; CHECK: ret i1 true } define i1 @maxmin8(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @maxmin8( +; CHECK: ret i1 false +; %c1 = icmp uge i32 %x, %y %max = select i1 %c1, i32 %x, i32 %y %c2 = icmp uge i32 %x, %z %min = select i1 %c2, i32 %z, i32 %x %c = icmp ult i32 %max, %min ret i1 %c -; CHECK: ret i1 false } define i1 @eqcmp1(i32 %x, i32 %y) { ; CHECK-LABEL: @eqcmp1( +; CHECK: [[C:%.*]] = icmp sge i32 %x, %y +; CHECK-NEXT: ret i1 [[C]] +; %c = icmp sge i32 %x, %y %max = select i1 %c, i32 %x, i32 %y %r = icmp eq i32 %max, %x ret i1 %r -; CHECK: ret i1 %c } define i1 @eqcmp2(i32 %x, i32 %y) { ; CHECK-LABEL: @eqcmp2( +; CHECK: [[C:%.*]] = icmp sge i32 %x, %y +; CHECK-NEXT: ret i1 [[C]] +; %c = icmp sge i32 %x, %y %max = select i1 %c, i32 %x, i32 %y %r = icmp eq i32 %x, %max ret i1 %r -; CHECK: ret i1 %c } define i1 @eqcmp3(i32 %x, i32 %y) { ; CHECK-LABEL: @eqcmp3( +; CHECK: [[C:%.*]] = icmp uge i32 %x, %y +; CHECK-NEXT: ret i1 [[C]] +; %c = icmp uge i32 %x, %y %max = select i1 %c, i32 %x, i32 %y %r = icmp eq i32 %max, %x ret i1 %r -; CHECK: ret i1 %c } define i1 @eqcmp4(i32 %x, i32 %y) { ; CHECK-LABEL: @eqcmp4( +; CHECK: [[C:%.*]] = icmp uge i32 %x, %y +; CHECK-NEXT: ret i1 [[C]] +; %c = icmp uge i32 %x, %y %max = select i1 %c, i32 %x, i32 %y %r = icmp eq i32 %x, %max ret i1 %r -; CHECK: ret i1 %c } diff --git a/llvm/test/Transforms/InstSimplify/past-the-end.ll b/llvm/test/Transforms/InstSimplify/past-the-end.ll index b676e9d..b47db7d 100644 --- a/llvm/test/Transforms/InstSimplify/past-the-end.ll +++ b/llvm/test/Transforms/InstSimplify/past-the-end.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s target datalayout = "p:32:32" @@ -9,21 +10,23 @@ target datalayout = "p:32:32" ; Comparing base addresses of two distinct globals. Never equal. define zeroext i1 @no_offsets() { +; CHECK-LABEL: @no_offsets( +; CHECK: ret i1 false +; %t = icmp eq i32* @opte_a, @opte_b ret i1 %t - ; CHECK: no_offsets( - ; CHECK: ret i1 false } ; Comparing past-the-end addresses of two distinct globals. Never equal. define zeroext i1 @both_past_the_end() { +; CHECK-LABEL: @both_past_the_end( +; CHECK: ret i1 icmp eq (i32* getelementptr inbounds (i32, i32* @opte_a, i32 1), i32* getelementptr inbounds (i32, i32* @opte_b, i32 1)) +; %x = getelementptr i32, i32* @opte_a, i32 1 %y = getelementptr i32, i32* @opte_b, i32 1 %t = icmp eq i32* %x, %y ret i1 %t - ; CHECK: both_past_the_end( - ; CHECK-NOT: ret i1 true ; TODO: refine this } @@ -31,35 +34,43 @@ define zeroext i1 @both_past_the_end() { ; of another. Can't fold this. define zeroext i1 @just_one_past_the_end() { +; CHECK-LABEL: @just_one_past_the_end( +; CHECK: ret i1 icmp eq (i32* getelementptr inbounds (i32, i32* @opte_a, i32 1), i32* @opte_b) +; %x = getelementptr i32, i32* @opte_a, i32 1 %t = icmp eq i32* %x, @opte_b ret i1 %t - ; CHECK: just_one_past_the_end( - ; CHECK: ret i1 icmp eq (i32* getelementptr inbounds (i32, i32* @opte_a, i32 1), i32* @opte_b) } ; Comparing base addresses of two distinct allocas. Never equal. define zeroext i1 @no_alloca_offsets() { +; CHECK-LABEL: @no_alloca_offsets( +; CHECK: ret i1 false +; %m = alloca i32 %n = alloca i32 %t = icmp eq i32* %m, %n ret i1 %t - ; CHECK: no_alloca_offsets( - ; CHECK: ret i1 false } ; Comparing past-the-end addresses of two distinct allocas. Never equal. define zeroext i1 @both_past_the_end_alloca() { +; CHECK-LABEL: @both_past_the_end_alloca( +; CHECK: [[M:%.*]] = alloca i32 +; CHECK-NEXT: [[N:%.*]] = alloca i32 +; CHECK-NEXT: [[X:%.*]] = getelementptr i32, i32* [[M]], i32 1 +; CHECK-NEXT: [[Y:%.*]] = getelementptr i32, i32* [[N]], i32 1 +; CHECK-NEXT: [[T:%.*]] = icmp eq i32* [[X]], [[Y]] +; CHECK-NEXT: ret i1 [[T]] +; %m = alloca i32 %n = alloca i32 %x = getelementptr i32, i32* %m, i32 1 %y = getelementptr i32, i32* %n, i32 1 %t = icmp eq i32* %x, %y ret i1 %t - ; CHECK: both_past_the_end_alloca( - ; CHECK-NOT: ret i1 true ; TODO: refine this } @@ -67,11 +78,16 @@ define zeroext i1 @both_past_the_end_alloca() { ; of another. Can't fold this. define zeroext i1 @just_one_past_the_end_alloca() { +; CHECK-LABEL: @just_one_past_the_end_alloca( +; CHECK: [[M:%.*]] = alloca i32 +; CHECK-NEXT: [[N:%.*]] = alloca i32 +; CHECK-NEXT: [[X:%.*]] = getelementptr i32, i32* [[M]], i32 1 +; CHECK-NEXT: [[T:%.*]] = icmp eq i32* [[X]], [[N]] +; CHECK-NEXT: ret i1 [[T]] +; %m = alloca i32 %n = alloca i32 %x = getelementptr i32, i32* %m, i32 1 %t = icmp eq i32* %x, %n ret i1 %t - ; CHECK: just_one_past_the_end_alloca( - ; CHECK: ret i1 %t } diff --git a/llvm/test/Transforms/InstSimplify/phi.ll b/llvm/test/Transforms/InstSimplify/phi.ll index 5b7aaa9..b0040ff 100644 --- a/llvm/test/Transforms/InstSimplify/phi.ll +++ b/llvm/test/Transforms/InstSimplify/phi.ll @@ -1,8 +1,11 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s ; PR12189 define i1 @test1(i32 %x) { ; CHECK-LABEL: @test1( +; CHECK: ret i1 %e +; br i1 true, label %a, label %b a: @@ -18,5 +21,4 @@ c: %d = urem i32 %cc, 2 %e = icmp eq i32 %d, 0 ret i1 %e -; CHECK: ret i1 %e } diff --git a/llvm/test/Transforms/InstSimplify/ptr_diff.ll b/llvm/test/Transforms/InstSimplify/ptr_diff.ll index 6c27e6f..c57fab9 100644 --- a/llvm/test/Transforms/InstSimplify/ptr_diff.ll +++ b/llvm/test/Transforms/InstSimplify/ptr_diff.ll @@ -1,11 +1,12 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" define i64 @ptrdiff1(i8* %ptr) { ; CHECK-LABEL: @ptrdiff1( -; CHECK-NEXT: ret i64 42 - +; CHECK: ret i64 42 +; %first = getelementptr inbounds i8, i8* %ptr, i32 0 %last = getelementptr inbounds i8, i8* %ptr, i32 42 %first.int = ptrtoint i8* %first to i64 @@ -16,8 +17,8 @@ define i64 @ptrdiff1(i8* %ptr) { define i64 @ptrdiff2(i8* %ptr) { ; CHECK-LABEL: @ptrdiff2( -; CHECK-NEXT: ret i64 42 - +; CHECK: ret i64 42 +; %first1 = getelementptr inbounds i8, i8* %ptr, i32 0 %first2 = getelementptr inbounds i8, i8* %first1, i32 1 %first3 = getelementptr inbounds i8, i8* %first2, i32 2 @@ -35,10 +36,12 @@ define i64 @ptrdiff2(i8* %ptr) { define i64 @ptrdiff3(i8* %ptr) { ; Don't bother with non-inbounds GEPs. ; CHECK-LABEL: @ptrdiff3( -; CHECK: getelementptr -; CHECK: sub -; CHECK: ret - +; CHECK: [[LAST:%.*]] = getelementptr i8, i8* %ptr, i32 42 +; CHECK-NEXT: [[FIRST_INT:%.*]] = ptrtoint i8* %ptr to i64 +; CHECK-NEXT: [[LAST_INT:%.*]] = ptrtoint i8* [[LAST]] to i64 +; CHECK-NEXT: [[DIFF:%.*]] = sub i64 [[LAST_INT]], [[FIRST_INT]] +; CHECK-NEXT: ret i64 [[DIFF]] +; %first = getelementptr i8, i8* %ptr, i32 0 %last = getelementptr i8, i8* %ptr, i32 42 %first.int = ptrtoint i8* %first to i64 @@ -50,7 +53,8 @@ define i64 @ptrdiff3(i8* %ptr) { define <4 x i32> @ptrdiff4(<4 x i8*> %arg) nounwind { ; Handle simple cases of vectors of pointers. ; CHECK-LABEL: @ptrdiff4( -; CHECK: ret <4 x i32> zeroinitializer +; CHECK: ret <4 x i32> zeroinitializer +; %p1 = ptrtoint <4 x i8*> %arg to <4 x i32> %bc = bitcast <4 x i8*> %arg to <4 x i32*> %p2 = ptrtoint <4 x i32*> %bc to <4 x i32> @@ -63,6 +67,10 @@ define <4 x i32> @ptrdiff4(<4 x i8*> %arg) nounwind { @global = internal global %struct.ham zeroinitializer, align 4 define i32 @ptrdiff5() nounwind { +; CHECK-LABEL: @ptrdiff5( +; CHECK: bb: +; CHECK-NEXT: ret i32 0 +; bb: %tmp = getelementptr inbounds %struct.ham, %struct.ham* @global, i32 0, i32 1 %tmp1 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %tmp, i32 0, i32 0 @@ -73,6 +81,4 @@ bb: %tmp6 = ptrtoint [2 x i32]* %tmp5 to i32 %tmp7 = sub i32 %tmp3, %tmp6 ret i32 %tmp7 -; CHECK-LABEL: @ptrdiff5( -; CHECK: ret i32 0 } diff --git a/llvm/test/Transforms/InstSimplify/reassociate.ll b/llvm/test/Transforms/InstSimplify/reassociate.ll index d44f715..335df32 100644 --- a/llvm/test/Transforms/InstSimplify/reassociate.ll +++ b/llvm/test/Transforms/InstSimplify/reassociate.ll @@ -1,195 +1,223 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s define i32 @add1(i32 %x) { ; CHECK-LABEL: @add1( +; CHECK: ret i32 %x +; ; (X + -1) + 1 -> X %l = add i32 %x, -1 %r = add i32 %l, 1 ret i32 %r -; CHECK: ret i32 %x } define i32 @and1(i32 %x, i32 %y) { ; CHECK-LABEL: @and1( +; CHECK: [[L:%.*]] = and i32 %x, %y +; CHECK-NEXT: ret i32 [[L]] +; ; (X & Y) & X -> X & Y %l = and i32 %x, %y %r = and i32 %l, %x ret i32 %r -; CHECK: ret i32 %l } define i32 @and2(i32 %x, i32 %y) { ; CHECK-LABEL: @and2( +; CHECK: [[R:%.*]] = and i32 %x, %y +; CHECK-NEXT: ret i32 [[R]] +; ; X & (X & Y) -> X & Y %r = and i32 %x, %y %l = and i32 %x, %r ret i32 %l -; CHECK: ret i32 %r } define i32 @or1(i32 %x, i32 %y) { ; CHECK-LABEL: @or1( +; CHECK: [[L:%.*]] = or i32 %x, %y +; CHECK-NEXT: ret i32 [[L]] +; ; (X | Y) | X -> X | Y %l = or i32 %x, %y %r = or i32 %l, %x ret i32 %r -; CHECK: ret i32 %l } define i32 @or2(i32 %x, i32 %y) { ; CHECK-LABEL: @or2( +; CHECK: [[R:%.*]] = or i32 %x, %y +; CHECK-NEXT: ret i32 [[R]] +; ; X | (X | Y) -> X | Y %r = or i32 %x, %y %l = or i32 %x, %r ret i32 %l -; CHECK: ret i32 %r } define i32 @xor1(i32 %x, i32 %y) { ; CHECK-LABEL: @xor1( +; CHECK: ret i32 %y +; ; (X ^ Y) ^ X = Y %l = xor i32 %x, %y %r = xor i32 %l, %x ret i32 %r -; CHECK: ret i32 %y } define i32 @xor2(i32 %x, i32 %y) { ; CHECK-LABEL: @xor2( +; CHECK: ret i32 %y +; ; X ^ (X ^ Y) = Y %r = xor i32 %x, %y %l = xor i32 %x, %r ret i32 %l -; CHECK: ret i32 %y } define i32 @sub1(i32 %x, i32 %y) { ; CHECK-LABEL: @sub1( +; CHECK: ret i32 %y +; %d = sub i32 %x, %y %r = sub i32 %x, %d ret i32 %r -; CHECK: ret i32 %y } define i32 @sub2(i32 %x) { ; CHECK-LABEL: @sub2( +; CHECK: ret i32 -1 +; ; X - (X + 1) -> -1 %xp1 = add i32 %x, 1 %r = sub i32 %x, %xp1 ret i32 %r -; CHECK: ret i32 -1 } define i32 @sub3(i32 %x, i32 %y) { ; CHECK-LABEL: @sub3( +; CHECK: ret i32 %x +; ; ((X + 1) + Y) - (Y + 1) -> X %xp1 = add i32 %x, 1 %lhs = add i32 %xp1, %y %rhs = add i32 %y, 1 %r = sub i32 %lhs, %rhs ret i32 %r -; CHECK: ret i32 %x } define i32 @sdiv1(i32 %x, i32 %y) { ; CHECK-LABEL: @sdiv1( +; CHECK: ret i32 %x +; ; (no overflow X * Y) / Y -> X %mul = mul nsw i32 %x, %y %r = sdiv i32 %mul, %y ret i32 %r -; CHECK: ret i32 %x } define i32 @sdiv2(i32 %x, i32 %y) { ; CHECK-LABEL: @sdiv2( +; CHECK: [[DIV:%.*]] = sdiv i32 %x, %y +; CHECK-NEXT: ret i32 [[DIV]] +; ; (((X / Y) * Y) / Y) -> X / Y %div = sdiv i32 %x, %y %mul = mul i32 %div, %y %r = sdiv i32 %mul, %y ret i32 %r -; CHECK: ret i32 %div } define i32 @sdiv3(i32 %x, i32 %y) { ; CHECK-LABEL: @sdiv3( +; CHECK: ret i32 0 +; ; (X rem Y) / Y -> 0 %rem = srem i32 %x, %y %div = sdiv i32 %rem, %y ret i32 %div -; CHECK: ret i32 0 } define i32 @sdiv4(i32 %x, i32 %y) { ; CHECK-LABEL: @sdiv4( +; CHECK: ret i32 %x +; ; (X / Y) * Y -> X if the division is exact %div = sdiv exact i32 %x, %y %mul = mul i32 %div, %y ret i32 %mul -; CHECK: ret i32 %x } define i32 @sdiv5(i32 %x, i32 %y) { ; CHECK-LABEL: @sdiv5( +; CHECK: ret i32 %x +; ; Y * (X / Y) -> X if the division is exact %div = sdiv exact i32 %x, %y %mul = mul i32 %y, %div ret i32 %mul -; CHECK: ret i32 %x } define i32 @udiv1(i32 %x, i32 %y) { ; CHECK-LABEL: @udiv1( +; CHECK: ret i32 %x +; ; (no overflow X * Y) / Y -> X %mul = mul nuw i32 %x, %y %r = udiv i32 %mul, %y ret i32 %r -; CHECK: ret i32 %x } define i32 @udiv2(i32 %x, i32 %y) { ; CHECK-LABEL: @udiv2( +; CHECK: [[DIV:%.*]] = udiv i32 %x, %y +; CHECK-NEXT: ret i32 [[DIV]] +; ; (((X / Y) * Y) / Y) -> X / Y %div = udiv i32 %x, %y %mul = mul i32 %div, %y %r = udiv i32 %mul, %y ret i32 %r -; CHECK: ret i32 %div } define i32 @udiv3(i32 %x, i32 %y) { ; CHECK-LABEL: @udiv3( +; CHECK: ret i32 0 +; ; (X rem Y) / Y -> 0 %rem = urem i32 %x, %y %div = udiv i32 %rem, %y ret i32 %div -; CHECK: ret i32 0 } define i32 @udiv4(i32 %x, i32 %y) { ; CHECK-LABEL: @udiv4( +; CHECK: ret i32 %x +; ; (X / Y) * Y -> X if the division is exact %div = udiv exact i32 %x, %y %mul = mul i32 %div, %y ret i32 %mul -; CHECK: ret i32 %x } define i32 @udiv5(i32 %x, i32 %y) { ; CHECK-LABEL: @udiv5( +; CHECK: ret i32 %x +; ; Y * (X / Y) -> X if the division is exact %div = udiv exact i32 %x, %y %mul = mul i32 %y, %div ret i32 %mul -; CHECK: ret i32 %x } define i16 @trunc1(i32 %x) { ; CHECK-LABEL: @trunc1( +; CHECK: ret i16 1 +; %y = add i32 %x, 1 %tx = trunc i32 %x to i16 %ty = trunc i32 %y to i16 %d = sub i16 %ty, %tx ret i16 %d -; CHECK: ret i16 1 } diff --git a/llvm/test/Transforms/InstSimplify/rem.ll b/llvm/test/Transforms/InstSimplify/rem.ll index f5ea451..df3f659 100644 --- a/llvm/test/Transforms/InstSimplify/rem.ll +++ b/llvm/test/Transforms/InstSimplify/rem.ll @@ -1,25 +1,29 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt < %s -instsimplify -S | FileCheck %s define i32 @select1(i32 %x, i1 %b) { ; CHECK-LABEL: @select1( +; CHECK: ret i32 0 +; %rhs = select i1 %b, i32 %x, i32 1 %rem = srem i32 %x, %rhs ret i32 %rem -; CHECK: ret i32 0 } define i32 @select2(i32 %x, i1 %b) { ; CHECK-LABEL: @select2( +; CHECK: ret i32 0 +; %rhs = select i1 %b, i32 %x, i32 1 %rem = urem i32 %x, %rhs ret i32 %rem -; CHECK: ret i32 0 } define i32 @rem1(i32 %x, i32 %n) { ; CHECK-LABEL: @rem1( -; CHECK-NEXT: %mod = srem i32 %x, %n -; CHECK-NEXT: ret i32 %mod +; CHECK: [[MOD:%.*]] = srem i32 %x, %n +; CHECK-NEXT: ret i32 [[MOD]] +; %mod = srem i32 %x, %n %mod1 = srem i32 %mod, %n ret i32 %mod1 @@ -27,8 +31,9 @@ define i32 @rem1(i32 %x, i32 %n) { define i32 @rem2(i32 %x, i32 %n) { ; CHECK-LABEL: @rem2( -; CHECK-NEXT: %mod = urem i32 %x, %n -; CHECK-NEXT: ret i32 %mod +; CHECK: [[MOD:%.*]] = urem i32 %x, %n +; CHECK-NEXT: ret i32 [[MOD]] +; %mod = urem i32 %x, %n %mod1 = urem i32 %mod, %n ret i32 %mod1 @@ -36,9 +41,10 @@ define i32 @rem2(i32 %x, i32 %n) { define i32 @rem3(i32 %x, i32 %n) { ; CHECK-LABEL: @rem3( -; CHECK-NEXT: %[[srem:.*]] = srem i32 %x, %n -; CHECK-NEXT: %[[urem:.*]] = urem i32 %[[srem]], %n -; CHECK-NEXT: ret i32 %[[urem]] +; CHECK: [[MOD:%.*]] = srem i32 %x, %n +; CHECK-NEXT: [[MOD1:%.*]] = urem i32 [[MOD]], %n +; CHECK-NEXT: ret i32 [[MOD1]] +; %mod = srem i32 %x, %n %mod1 = urem i32 %mod, %n ret i32 %mod1 diff --git a/llvm/test/Transforms/InstSimplify/shift-128-kb.ll b/llvm/test/Transforms/InstSimplify/shift-128-kb.ll index 3f69ecc..76f1da5 100644 --- a/llvm/test/Transforms/InstSimplify/shift-128-kb.ll +++ b/llvm/test/Transforms/InstSimplify/shift-128-kb.ll @@ -1,9 +1,21 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt -S -instsimplify < %s | FileCheck %s target datalayout = "E-m:e-i64:64-n32:64" target triple = "powerpc64-unknown-linux-gnu" define zeroext i1 @_Z10isNegativemj(i64 %Val, i32 zeroext %IntegerBitWidth) { +; CHECK-LABEL: @_Z10isNegativemj( +; CHECK: [[CONV:%.*]] = zext i32 %IntegerBitWidth to i64 +; CHECK-NEXT: [[SUB:%.*]] = sub i64 128, [[CONV]] +; CHECK-NEXT: [[CONV1:%.*]] = trunc i64 [[SUB]] to i32 +; CHECK-NEXT: [[CONV2:%.*]] = zext i64 %Val to i128 +; CHECK-NEXT: [[SH_PROM:%.*]] = zext i32 [[CONV1]] to i128 +; CHECK-NEXT: [[SHL:%.*]] = shl i128 [[CONV2]], [[SH_PROM]] +; CHECK-NEXT: [[SHR:%.*]] = ashr i128 [[SHL]], [[SH_PROM]] +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[SHR]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; entry: %conv = zext i32 %IntegerBitWidth to i64 %sub = sub i64 128, %conv @@ -16,7 +28,3 @@ entry: ret i1 %cmp } -; CHECK-LABEL: @_Z10isNegativemj -; CHECK-NOT: ret i1 false -; CHECK: ret i1 %cmp - diff --git a/llvm/test/Transforms/InstSimplify/undef.ll b/llvm/test/Transforms/InstSimplify/undef.ll index 6141180..b92184b 100644 --- a/llvm/test/Transforms/InstSimplify/undef.ll +++ b/llvm/test/Transforms/InstSimplify/undef.ll @@ -1,302 +1,347 @@ +; NOTE: Assertions have been autogenerated by update_test_checks.py ; RUN: opt -instsimplify -S < %s | FileCheck %s -; @test0 -; CHECK: ret i64 undef define i64 @test0() { +; CHECK-LABEL: @test0( +; CHECK: ret i64 undef +; %r = mul i64 undef, undef ret i64 %r } -; @test1 -; CHECK: ret i64 undef define i64 @test1() { +; CHECK-LABEL: @test1( +; CHECK: ret i64 undef +; %r = mul i64 3, undef ret i64 %r } -; @test2 -; CHECK: ret i64 undef define i64 @test2() { +; CHECK-LABEL: @test2( +; CHECK: ret i64 undef +; %r = mul i64 undef, 3 ret i64 %r } -; @test3 -; CHECK: ret i64 0 define i64 @test3() { +; CHECK-LABEL: @test3( +; CHECK: ret i64 0 +; %r = mul i64 undef, 6 ret i64 %r } -; @test4 -; CHECK: ret i64 0 define i64 @test4() { +; CHECK-LABEL: @test4( +; CHECK: ret i64 0 +; %r = mul i64 6, undef ret i64 %r } -; @test5 -; CHECK: ret i64 undef define i64 @test5() { +; CHECK-LABEL: @test5( +; CHECK: ret i64 undef +; %r = and i64 undef, undef ret i64 %r } -; @test6 -; CHECK: ret i64 undef define i64 @test6() { +; CHECK-LABEL: @test6( +; CHECK: ret i64 undef +; %r = or i64 undef, undef ret i64 %r } -; @test7 -; CHECK: ret i64 undef define i64 @test7() { +; CHECK-LABEL: @test7( +; CHECK: ret i64 undef +; %r = udiv i64 undef, 1 ret i64 %r } -; @test8 -; CHECK: ret i64 undef define i64 @test8() { +; CHECK-LABEL: @test8( +; CHECK: ret i64 undef +; %r = sdiv i64 undef, 1 ret i64 %r } -; @test9 -; CHECK: ret i64 0 define i64 @test9() { +; CHECK-LABEL: @test9( +; CHECK: ret i64 0 +; %r = urem i64 undef, 1 ret i64 %r } -; @test10 -; CHECK: ret i64 0 define i64 @test10() { +; CHECK-LABEL: @test10( +; CHECK: ret i64 0 +; %r = srem i64 undef, 1 ret i64 %r } -; @test11 -; CHECK: ret i64 undef define i64 @test11() { +; CHECK-LABEL: @test11( +; CHECK: ret i64 undef +; %r = shl i64 undef, undef ret i64 %r } -; @test11b -; CHECK: ret i64 undef define i64 @test11b(i64 %a) { +; CHECK-LABEL: @test11b( +; CHECK: ret i64 undef +; %r = shl i64 %a, undef ret i64 %r } -; @test12 -; CHECK: ret i64 undef define i64 @test12() { +; CHECK-LABEL: @test12( +; CHECK: ret i64 undef +; %r = ashr i64 undef, undef ret i64 %r } -; @test12b -; CHECK: ret i64 undef define i64 @test12b(i64 %a) { +; CHECK-LABEL: @test12b( +; CHECK: ret i64 undef +; %r = ashr i64 %a, undef ret i64 %r } -; @test13 -; CHECK: ret i64 undef define i64 @test13() { +; CHECK-LABEL: @test13( +; CHECK: ret i64 undef +; %r = lshr i64 undef, undef ret i64 %r } -; @test13b -; CHECK: ret i64 undef define i64 @test13b(i64 %a) { +; CHECK-LABEL: @test13b( +; CHECK: ret i64 undef +; %r = lshr i64 %a, undef ret i64 %r } -; @test14 -; CHECK: ret i1 undef define i1 @test14() { +; CHECK-LABEL: @test14( +; CHECK: ret i1 undef +; %r = icmp slt i64 undef, undef ret i1 %r } -; @test15 -; CHECK: ret i1 undef define i1 @test15() { +; CHECK-LABEL: @test15( +; CHECK: ret i1 undef +; %r = icmp ult i64 undef, undef ret i1 %r } -; @test16 -; CHECK: ret i64 undef define i64 @test16(i64 %a) { +; CHECK-LABEL: @test16( +; CHECK: ret i64 undef +; %r = select i1 undef, i64 %a, i64 undef ret i64 %r } -; @test17 -; CHECK: ret i64 undef define i64 @test17(i64 %a) { +; CHECK-LABEL: @test17( +; CHECK: ret i64 undef +; %r = select i1 undef, i64 undef, i64 %a ret i64 %r } -; @test18 -; CHECK: ret i64 undef define i64 @test18(i64 %a) { +; CHECK-LABEL: @test18( +; CHECK: [[R:%.*]] = call i64 undef(i64 %a) +; CHECK-NEXT: ret i64 undef +; %r = call i64 (i64) undef(i64 %a) ret i64 %r } -; CHECK-LABEL: @test19 -; CHECK: ret <4 x i8> undef define <4 x i8> @test19(<4 x i8> %a) { +; CHECK-LABEL: @test19( +; CHECK: ret <4 x i8> undef +; %b = shl <4 x i8> %a, ret <4 x i8> %b } -; CHECK-LABEL: @test20 -; CHECK: ret i32 undef define i32 @test20(i32 %a) { +; CHECK-LABEL: @test20( +; CHECK: ret i32 undef +; %b = udiv i32 %a, 0 ret i32 %b } -; CHECK-LABEL: @test21 -; CHECK: ret i32 undef define i32 @test21(i32 %a) { +; CHECK-LABEL: @test21( +; CHECK: ret i32 undef +; %b = sdiv i32 %a, 0 ret i32 %b } -; CHECK-LABEL: @test22 -; CHECK: ret i32 undef define i32 @test22(i32 %a) { +; CHECK-LABEL: @test22( +; CHECK: ret i32 undef +; %b = ashr exact i32 undef, %a ret i32 %b } -; CHECK-LABEL: @test23 -; CHECK: ret i32 undef define i32 @test23(i32 %a) { +; CHECK-LABEL: @test23( +; CHECK: ret i32 undef +; %b = lshr exact i32 undef, %a ret i32 %b } -; CHECK-LABEL: @test24 -; CHECK: ret i32 undef define i32 @test24() { +; CHECK-LABEL: @test24( +; CHECK: ret i32 undef +; %b = udiv i32 undef, 0 ret i32 %b } -; CHECK-LABEL: @test25 -; CHECK: ret i32 undef define i32 @test25() { +; CHECK-LABEL: @test25( +; CHECK: ret i32 undef +; %b = lshr i32 0, undef ret i32 %b } -; CHECK-LABEL: @test26 -; CHECK: ret i32 undef define i32 @test26() { +; CHECK-LABEL: @test26( +; CHECK: ret i32 undef +; %b = ashr i32 0, undef ret i32 %b } -; CHECK-LABEL: @test27 -; CHECK: ret i32 undef define i32 @test27() { +; CHECK-LABEL: @test27( +; CHECK: ret i32 undef +; %b = shl i32 0, undef ret i32 %b } -; CHECK-LABEL: @test28 -; CHECK: ret i32 undef define i32 @test28(i32 %a) { +; CHECK-LABEL: @test28( +; CHECK: ret i32 undef +; %b = shl nsw i32 undef, %a ret i32 %b } -; CHECK-LABEL: @test29 -; CHECK: ret i32 undef define i32 @test29(i32 %a) { +; CHECK-LABEL: @test29( +; CHECK: ret i32 undef +; %b = shl nuw i32 undef, %a ret i32 %b } -; CHECK-LABEL: @test30 -; CHECK: ret i32 undef define i32 @test30(i32 %a) { +; CHECK-LABEL: @test30( +; CHECK: ret i32 undef +; %b = shl nsw nuw i32 undef, %a ret i32 %b } -; CHECK-LABEL: @test31 -; CHECK: ret i32 0 define i32 @test31(i32 %a) { +; CHECK-LABEL: @test31( +; CHECK: ret i32 0 +; %b = shl i32 undef, %a ret i32 %b } -; CHECK-LABEL: @test32 -; CHECK: ret i32 undef define i32 @test32(i32 %a) { +; CHECK-LABEL: @test32( +; CHECK: ret i32 undef +; %b = shl i32 undef, 0 ret i32 %b } -; CHECK-LABEL: @test33 -; CHECK: ret i32 undef define i32 @test33(i32 %a) { +; CHECK-LABEL: @test33( +; CHECK: ret i32 undef +; %b = ashr i32 undef, 0 ret i32 %b } -; CHECK-LABEL: @test34 -; CHECK: ret i32 undef define i32 @test34(i32 %a) { +; CHECK-LABEL: @test34( +; CHECK: ret i32 undef +; %b = lshr i32 undef, 0 ret i32 %b } -; CHECK-LABEL: @test35 -; CHECK: ret i32 undef define i32 @test35(<4 x i32> %V) { +; CHECK-LABEL: @test35( +; CHECK: ret i32 undef +; %b = extractelement <4 x i32> %V, i32 4 ret i32 %b } -; CHECK-LABEL: @test36 -; CHECK: ret i32 undef define i32 @test36(i32 %V) { +; CHECK-LABEL: @test36( +; CHECK: ret i32 undef +; %b = extractelement <4 x i32> undef, i32 %V ret i32 %b } -; CHECK-LABEL: @test37 -; CHECK: ret i32 undef define i32 @test37() { +; CHECK-LABEL: @test37( +; CHECK: ret i32 undef +; %b = udiv i32 undef, undef ret i32 %b } -; CHECK-LABEL: @test38 -; CHECK: ret i32 undef define i32 @test38(i32 %a) { +; CHECK-LABEL: @test38( +; CHECK: ret i32 undef +; %b = udiv i32 %a, undef ret i32 %b } -; CHECK-LABEL: @test39 -; CHECK: ret i32 undef define i32 @test39() { +; CHECK-LABEL: @test39( +; CHECK: ret i32 undef +; %b = udiv i32 0, undef ret i32 %b }