From 421092465e5ac7c32e5b33281ffcaaef016d2a9e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 8 Feb 2017 22:14:11 +0000 Subject: [PATCH] [InstCombine] add tests to show information-losing add nsw/nuw transforms; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294524 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/add.ll | 43 ++++++++++++++++++++++--- test/Transforms/InstCombine/icmp-add.ll | 24 ++++++++++++++ test/Transforms/InstCombine/sub-xor.ll | 10 ------ 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/test/Transforms/InstCombine/add.ll b/test/Transforms/InstCombine/add.ll index 3ea78492470..03b2c3e8571 100644 --- a/test/Transforms/InstCombine/add.ll +++ b/test/Transforms/InstCombine/add.ll @@ -244,14 +244,49 @@ define i32 @test19(i1 %C) { ret i32 %V } +; Add of sign bit -> xor of sign bit. + define i32 @test20(i32 %x) { ; CHECK-LABEL: @test20( ; CHECK-NEXT: ret i32 %x ; - %tmp.2 = xor i32 %x, -2147483648 - ;; Add of sign bit -> xor of sign bit. - %tmp.4 = add i32 %tmp.2, -2147483648 - ret i32 %tmp.4 + %y = xor i32 %x, -2147483648 + %z = add nsw i32 %y, -2147483648 + ret i32 %z +} + +define i32 @xor_sign_bit(i32 %x) { +; CHECK-LABEL: @xor_sign_bit( +; CHECK-NEXT: [[ADD:%.*]] = add i32 %x, -2147483606 +; CHECK-NEXT: ret i32 [[ADD]] +; + %xor = xor i32 %x, 2147483648 + %add = add i32 %xor, 42 + ret i32 %add +} + +; Lose no-wrap info by converting to xor? %x is known non-negative +; here, but not after converting to xor. + +define i8 @add_nsw_signbit(i8 %x) { +; CHECK-LABEL: @add_nsw_signbit( +; CHECK-NEXT: [[Y:%.*]] = xor i8 %x, -128 +; CHECK-NEXT: ret i8 [[Y]] +; + %y = add nsw i8 %x, -128 + ret i8 %y +} + +; Lose no-wrap info by converting to xor? %x is known non-negative +; (x < 128 unsigned), but not after converting to xor. + +define i8 @add_nuw_signbit(i8 %x) { +; CHECK-LABEL: @add_nuw_signbit( +; CHECK-NEXT: [[Y:%.*]] = xor i8 %x, -128 +; CHECK-NEXT: ret i8 [[Y]] +; + %y = add nuw i8 %x, 128 + ret i8 %y } define i1 @test21(i32 %x) { diff --git a/test/Transforms/InstCombine/icmp-add.ll b/test/Transforms/InstCombine/icmp-add.ll index 3bf1849c91c..d00875f9a66 100644 --- a/test/Transforms/InstCombine/icmp-add.ll +++ b/test/Transforms/InstCombine/icmp-add.ll @@ -106,3 +106,27 @@ define <2 x i1> @slt_zero_add_nsw_splat_vec(<2 x i8> %a) { ret <2 x i1> %cmp } +; FIXME: InstCombine should not lose wrapping information by changing the add to xor. + +define i1 @slt_zero_add_nsw_signbit(i8 %x) { +; CHECK-LABEL: @slt_zero_add_nsw_signbit( +; CHECK-NEXT: [[Z:%.*]] = icmp sgt i8 %x, -1 +; CHECK-NEXT: ret i1 [[Z]] +; + %y = add nsw i8 %x, -128 + %z = icmp slt i8 %y, 0 + ret i1 %z +} + +; FIXME: InstCombine should not lose wrapping information by changing the add to xor. + +define i1 @slt_zero_add_nuw_signbit(i8 %x) { +; CHECK-LABEL: @slt_zero_add_nuw_signbit( +; CHECK-NEXT: [[Z:%.*]] = icmp sgt i8 %x, -1 +; CHECK-NEXT: ret i1 [[Z]] +; + %y = add nuw i8 %x, 128 + %z = icmp slt i8 %y, 0 + ret i1 %z +} + diff --git a/test/Transforms/InstCombine/sub-xor.ll b/test/Transforms/InstCombine/sub-xor.ll index 9a0814c2c92..812305d8e48 100644 --- a/test/Transforms/InstCombine/sub-xor.ll +++ b/test/Transforms/InstCombine/sub-xor.ll @@ -48,13 +48,3 @@ define i32 @test3(i32 %x) { ret i32 %add } -define i32 @test4(i32 %x) { -; CHECK-LABEL: @test4( -; CHECK-NEXT: [[ADD:%.*]] = add i32 %x, -2147483606 -; CHECK-NEXT: ret i32 [[ADD]] -; - %sub = xor i32 %x, 2147483648 - %add = add i32 %sub, 42 - ret i32 %add -} - -- 2.50.1