diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-10-19 17:26:22 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-10-19 17:26:22 +0000 |
commit | ce3f1915f38f329a867dfb10ed1e82b49d4b52dc (patch) | |
tree | 50bfece3136aa6e68deac4e5726dd64b7d77c816 /llvm/test/Transforms/InstCombine/sub.ll | |
parent | 749c1b597a8f2f544d285e9cf5fe18552a3a0137 (diff) | |
download | bcm5719-llvm-ce3f1915f38f329a867dfb10ed1e82b49d4b52dc.tar.gz bcm5719-llvm-ce3f1915f38f329a867dfb10ed1e82b49d4b52dc.zip |
[InstCombine] move/add tests for sub/neg; NFC
These should all be handled using "dyn_castNegVal",
but that misses vectors with undef elements.
llvm-svn: 344790
Diffstat (limited to 'llvm/test/Transforms/InstCombine/sub.ll')
-rw-r--r-- | llvm/test/Transforms/InstCombine/sub.ll | 227 |
1 files changed, 175 insertions, 52 deletions
diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll index 8a568602f2b..299633b25ac 100644 --- a/llvm/test/Transforms/InstCombine/sub.ll +++ b/llvm/test/Transforms/InstCombine/sub.ll @@ -1,43 +1,175 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S | FileCheck %s + target datalayout = "e-p:64:64:64-p1:16:16:16-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" -; Optimize subtracts. +define i32 @sub_constant(i32 %x) { +; CHECK-LABEL: @sub_constant( +; CHECK-NEXT: [[R:%.*]] = add i32 [[X:%.*]], -42 +; CHECK-NEXT: ret i32 [[R]] ; -; RUN: opt < %s -instcombine -S | FileCheck %s + %r = sub i32 %x, 42 + ret i32 %r +} + +@g = global i32 0 -define i32 @test1(i32 %A) { -; CHECK-LABEL: @test1( -; CHECK-NEXT: ret i32 0 +define i32 @sub_constant_expression(i32 %x) { +; CHECK-LABEL: @sub_constant_expression( +; CHECK-NEXT: [[R:%.*]] = sub i32 [[X:%.*]], ptrtoint (i32* @g to i32) +; CHECK-NEXT: ret i32 [[R]] ; - %B = sub i32 %A, %A - ret i32 %B + %r = sub i32 %x, ptrtoint (i32* @g to i32) + ret i32 %r } -define i32 @test2(i32 %A) { -; CHECK-LABEL: @test2( -; CHECK-NEXT: ret i32 [[A:%.*]] +define <2 x i32> @sub_constant_vec(<2 x i32> %x) { +; CHECK-LABEL: @sub_constant_vec( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[X:%.*]], <i32 -42, i32 12> +; CHECK-NEXT: ret <2 x i32> [[R]] ; - %B = sub i32 %A, 0 - ret i32 %B + %r = sub <2 x i32> %x, <i32 42, i32 -12> + ret <2 x i32> %r } -define i32 @test3(i32 %A) { -; CHECK-LABEL: @test3( -; CHECK-NEXT: ret i32 [[A:%.*]] +define <3 x i33> @sub_constant_vec_weird_type(<3 x i33> %x) { +; CHECK-LABEL: @sub_constant_vec_weird_type( +; CHECK-NEXT: [[R:%.*]] = add <3 x i33> [[X:%.*]], <i33 42, i33 -42, i33 12> +; CHECK-NEXT: ret <3 x i33> [[R]] ; - %B = sub i32 0, %A - %C = sub i32 0, %B - ret i32 %C + %r = sub <3 x i33> %x, <i33 -42, i33 42, i33 -12> + ret <3 x i33> %r } -define i32 @test4(i32 %A, i32 %x) { -; CHECK-LABEL: @test4( -; CHECK-NEXT: [[C:%.*]] = add i32 [[X:%.*]], [[A:%.*]] -; CHECK-NEXT: ret i32 [[C]] +define <4 x i32> @sub_constant_expression_vec(<4 x i32> %x) { +; CHECK-LABEL: @sub_constant_expression_vec( +; CHECK-NEXT: [[R:%.*]] = sub <4 x i32> [[X:%.*]], bitcast (i128 ptrtoint (i32* @g to i128) to <4 x i32>) +; CHECK-NEXT: ret <4 x i32> [[R]] ; - %B = sub i32 0, %A - %C = sub i32 %x, %B - ret i32 %C + %r = sub <4 x i32> %x, bitcast (i128 ptrtoint (i32* @g to i128) to <4 x i32>) + ret <4 x i32> %r +} + +define i32 @neg_sub(i32 %x, i32 %y) { +; CHECK-LABEL: @neg_sub( +; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %neg = sub i32 0, %x + %r = sub i32 %y, %neg + ret i32 %r +} + +define i32 @neg_nsw_sub(i32 %x, i32 %y) { +; CHECK-LABEL: @neg_nsw_sub( +; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %neg = sub nsw i32 0, %x + %r = sub i32 %y, %neg + ret i32 %r +} + +define i32 @neg_sub_nsw(i32 %x, i32 %y) { +; CHECK-LABEL: @neg_sub_nsw( +; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %neg = sub i32 0, %x + %r = sub nsw i32 %y, %neg + ret i32 %r +} + +define i32 @neg_nsw_sub_nsw(i32 %x, i32 %y) { +; CHECK-LABEL: @neg_nsw_sub_nsw( +; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %neg = sub nsw i32 0, %x + %r = sub nsw i32 %y, %neg + ret i32 %r +} + +define <2 x i32> @neg_sub_vec(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_sub_vec( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub <2 x i32> zeroinitializer, %x + %r = sub <2 x i32> %y, %neg + ret <2 x i32> %r +} + +define <2 x i32> @neg_nsw_sub_vec(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_nsw_sub_vec( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub nsw <2 x i32> zeroinitializer, %x + %r = sub <2 x i32> %y, %neg + ret <2 x i32> %r +} + +define <2 x i32> @neg_sub_nsw_vec(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_sub_nsw_vec( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub <2 x i32> zeroinitializer, %x + %r = sub nsw <2 x i32> %y, %neg + ret <2 x i32> %r +} + +define <2 x i32> @neg_nsw_sub_nsw_vec(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_nsw_sub_nsw_vec( +; CHECK-NEXT: [[R:%.*]] = add nsw <2 x i32> [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub nsw <2 x i32> zeroinitializer, %x + %r = sub nsw <2 x i32> %y, %neg + ret <2 x i32> %r +} + +define <2 x i32> @neg_sub_vec_undef(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_sub_vec_undef( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub <2 x i32> <i32 0, i32 undef>, %x + %r = sub <2 x i32> %y, %neg + ret <2 x i32> %r +} + +define <2 x i32> @neg_nsw_sub_vec_undef(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_nsw_sub_vec_undef( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub nsw <2 x i32> <i32 undef, i32 0>, %x + %r = sub <2 x i32> %y, %neg + ret <2 x i32> %r +} + +define <2 x i32> @neg_sub_nsw_vec_undef(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_sub_nsw_vec_undef( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub <2 x i32> <i32 undef, i32 0>, %x + %r = sub nsw <2 x i32> %y, %neg + ret <2 x i32> %r +} + +; TODO: This should not drop 'nsw'. + +define <2 x i32> @neg_nsw_sub_nsw_vec_undef(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @neg_nsw_sub_nsw_vec_undef( +; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %neg = sub nsw <2 x i32> <i32 0, i32 undef>, %x + %r = sub nsw <2 x i32> %y, %neg + ret <2 x i32> %r } ; (~X) - (~Y) --> Y - X @@ -499,7 +631,7 @@ define <2 x i32> @test27commutedvecmixed(<2 x i32> %x, <2 x i32> %y) { define i32 @test28(i32 %x, i32 %y, i32 %z) { ; CHECK-LABEL: @test28( -; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[Z:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[Y:%.*]], [[Z:%.*]] ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[TMP1]], [[X:%.*]] ; CHECK-NEXT: ret i32 [[SUB]] ; @@ -626,16 +758,6 @@ define i32 @test38(i32 %A) { ret i32 %sub } -define i32 @test39(i32 %A, i32 %x) { -; CHECK-LABEL: @test39( -; CHECK-NEXT: [[C:%.*]] = add i32 [[X:%.*]], [[A:%.*]] -; CHECK-NEXT: ret i32 [[C]] -; - %B = sub i32 0, %A - %C = sub nsw i32 %x, %B - ret i32 %C -} - define i16 @test40(i16 %a, i16 %b) { ; CHECK-LABEL: @test40( ; CHECK-NEXT: [[ASHR:%.*]] = ashr i16 [[A:%.*]], 1 @@ -921,7 +1043,8 @@ define i32 @test56(i32 %A, i32 %B) { ; %X = add i32 %A, %B %Y = sub i32 %A, %X - ret i32 %Y } + ret i32 %Y +} define i32 @test57(i32 %A, i32 %B) { ; CHECK-LABEL: @test57( @@ -930,22 +1053,22 @@ define i32 @test57(i32 %A, i32 %B) { ; %X = add i32 %B, %A %Y = sub i32 %A, %X - ret i32 %Y } + ret i32 %Y +} @dummy_global1 = external global i8* @dummy_global2 = external global i8* define i64 @test58([100 x [100 x i8]]* %foo, i64 %i, i64 %j) { -; CHECK-LABEL: @test58( -; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[J:%.*]], 4200 -; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[I:%.*]], 4200 -; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2:%.*]] [[TMP1:%.*]] -; CHECK-NEXT: ret i64 [[TMP3]] -; ; Note the reassociate pass and another instcombine pass will further optimize this to ; "%sub = i64 %i, %j, ret i64 %sub" -; ; gep1 and gep2 have only one use +; CHECK-LABEL: @test58( +; CHECK-NEXT: [[GEP2_OFFS:%.*]] = add i64 [[J:%.*]], 4200 +; CHECK-NEXT: [[GEP1_OFFS:%.*]] = add i64 [[I:%.*]], 4200 +; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[GEP1_OFFS]], [[GEP2_OFFS]] +; CHECK-NEXT: ret i64 [[TMP1]] +; %gep1 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %i %gep2 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %j %cast1 = ptrtoint i8* %gep1 to i64 @@ -956,11 +1079,11 @@ define i64 @test58([100 x [100 x i8]]* %foo, i64 %i, i64 %j) { define i64 @test59([100 x [100 x i8]]* %foo, i64 %i) { ; CHECK-LABEL: @test59( -; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %i -; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 0 +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO:%.*]], i64 0, i64 42, i64 [[I:%.*]] +; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO]], i64 0, i64 42, i64 0 ; CHECK-NEXT: store i8* [[GEP1]], i8** @dummy_global1, align 8 ; CHECK-NEXT: store i8* [[GEP2]], i8** @dummy_global2, align 8 -; CHECK-NEXT: ret i64 %i +; CHECK-NEXT: ret i64 [[I]] ; ; gep1 and gep2 have more than one uses %gep1 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 %i @@ -975,8 +1098,8 @@ define i64 @test59([100 x [100 x i8]]* %foo, i64 %i) { define i64 @test60([100 x [100 x i8]]* %foo, i64 %i, i64 %j) { ; CHECK-LABEL: @test60( -; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 %j, i64 %i -; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 0 +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO:%.*]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]] +; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO]], i64 0, i64 42, i64 0 ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint i8* [[GEP1]] to i64 ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint i8* [[GEP2]] to i64 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]] @@ -995,8 +1118,8 @@ define i64 @test60([100 x [100 x i8]]* %foo, i64 %i, i64 %j) { define i64 @test61([100 x [100 x i8]]* %foo, i64 %i, i64 %j) { ; CHECK-LABEL: @test61( -; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 42, i64 0 -; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %foo, i64 0, i64 %j, i64 %i +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO:%.*]], i64 0, i64 42, i64 0 +; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* [[FOO]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]] ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint i8* [[GEP1]] to i64 ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint i8* [[GEP2]] to i64 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]] |