diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2013-04-08 18:41:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2013-04-08 18:41:23 +0000 |
commit | 4a16efa3e43e35f0cc9efe3a67f620f0017c3d36 (patch) | |
tree | 06099edc18d30894081a822b756f117cbe0b8207 /test/Transforms/InstCombine | |
parent | 482e7bddf617ae804dc47133cb07eb4aa81e45de (diff) |
Notes
Diffstat (limited to 'test/Transforms/InstCombine')
75 files changed, 3224 insertions, 108 deletions
diff --git a/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll b/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll index 1da28562aae40..d266164fd8707 100644 --- a/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll +++ b/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll @@ -1,4 +1,4 @@ -; RUN: opt -S -instcombine %s | FileCheck %s +; RUN: opt -S -instcombine < %s | FileCheck %s ; PR2297 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" target triple = "i386-apple-darwin8" diff --git a/test/Transforms/InstCombine/2009-02-11-NotInitialized.ll b/test/Transforms/InstCombine/2009-02-11-NotInitialized.ll new file mode 100644 index 0000000000000..b66495d9cbaa3 --- /dev/null +++ b/test/Transforms/InstCombine/2009-02-11-NotInitialized.ll @@ -0,0 +1,14 @@ +; RUN: opt < %s -inline -instcombine -functionattrs | llvm-dis +; +; Check that nocapture attributes are added when run after an SCC pass. +; PR3520 + +define i32 @use(i8* %x) nounwind readonly { +; CHECK: @use(i8* nocapture %x) + %1 = tail call i64 @strlen(i8* %x) nounwind readonly + %2 = trunc i64 %1 to i32 + ret i32 %2 +} + +declare i64 @strlen(i8*) nounwind readonly +; CHECK: declare i64 @strlen(i8* nocapture) nounwind readonly diff --git a/test/Transforms/InstCombine/2010-03-03-ExtElim.ll b/test/Transforms/InstCombine/2010-03-03-ExtElim.ll index 2df12d670adbe..bb3159e1e6fa1 100644 --- a/test/Transforms/InstCombine/2010-03-03-ExtElim.ll +++ b/test/Transforms/InstCombine/2010-03-03-ExtElim.ll @@ -1,4 +1,4 @@ -; RUN: opt -instcombine -S %s | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s ; PR6486 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" diff --git a/test/Transforms/InstCombine/2010-05-30-memcpy-Struct.ll b/test/Transforms/InstCombine/2010-05-30-memcpy-Struct.ll new file mode 100644 index 0000000000000..09a96749f2606 --- /dev/null +++ b/test/Transforms/InstCombine/2010-05-30-memcpy-Struct.ll @@ -0,0 +1,20 @@ +; RUN: opt -instcombine -S < %s | FileCheck %s +; PR7265 + +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" +target triple = "x86_64-unknown-linux-gnu" + +%union.anon = type { i32, [4 x i8] } + +@.str = private constant [3 x i8] c"%s\00" + +define void @CopyEventArg(%union.anon* %ev) nounwind { +entry: + %call = call i32 (i8*, i8*, ...)* @sprintf(i8* undef, i8* getelementptr inbounds ([3 x i8]* @.str, i64 0, i64 0), %union.anon* %ev) nounwind +; CHECK: bitcast %union.anon* %ev to i8* +; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 + ret void +} + +declare i32 @sprintf(i8*, i8*, ...) + diff --git a/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll b/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll index eb28994756952..8001621979197 100644 --- a/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll +++ b/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll @@ -5,8 +5,8 @@ define i32 @main(i32 %argc) nounwind ssp { entry: %tmp3151 = trunc i32 %argc to i8 -; CHECK: %tmp3163 = shl i8 %tmp3162, 6 -; CHECK: and i8 %tmp3163, 64 +; CHECK: %0 = shl i8 %tmp3151, 5 +; CHECK: and i8 %0, 64 ; CHECK-NOT: shl ; CHECK-NOT: shr %tmp3161 = or i8 %tmp3151, -17 diff --git a/test/Transforms/InstCombine/2012-04-23-Neon-Intrinsics.ll b/test/Transforms/InstCombine/2012-04-23-Neon-Intrinsics.ll index 0907c490bb35d..2dedd44e2be10 100644 --- a/test/Transforms/InstCombine/2012-04-23-Neon-Intrinsics.ll +++ b/test/Transforms/InstCombine/2012-04-23-Neon-Intrinsics.ll @@ -50,7 +50,7 @@ entry: %b = add <4 x i32> zeroinitializer, %a ret <4 x i32> %b ; CHECK: entry: -; CHECK-NEXT: %a = tail call <4 x i32> @llvm.arm.neon.vmulls.v4i32(<4 x i16> <i16 2, i16 2, i16 2, i16 2>, <4 x i16> %x) nounwind +; CHECK-NEXT: %a = tail call <4 x i32> @llvm.arm.neon.vmulls.v4i32(<4 x i16> <i16 2, i16 2, i16 2, i16 2>, <4 x i16> %x) [[NUW:#[0-9]+]] ; CHECK-NEXT: ret <4 x i32> %a } @@ -66,3 +66,7 @@ entry: declare <4 x i32> @llvm.arm.neon.vmulls.v4i32(<4 x i16>, <4 x i16>) nounwind readnone declare <4 x i32> @llvm.arm.neon.vmullu.v4i32(<4 x i16>, <4 x i16>) nounwind readnone + +; CHECK: attributes #0 = { nounwind readnone ssp } +; CHECK: attributes #1 = { nounwind readnone } +; CHECK: attributes [[NUW]] = { nounwind } diff --git a/test/Transforms/InstCombine/2012-12-14-simp-vgep.ll b/test/Transforms/InstCombine/2012-12-14-simp-vgep.ll new file mode 100644 index 0000000000000..fc29b095e5ced --- /dev/null +++ b/test/Transforms/InstCombine/2012-12-14-simp-vgep.ll @@ -0,0 +1,10 @@ +; RUN: opt < %s -instcombine -S + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +define <4 x i32> @foo(<4 x i32*>* %in) { + %t17 = load <4 x i32*>* %in, align 8 + %t18 = icmp eq <4 x i32*> %t17, zeroinitializer + %t19 = zext <4 x i1> %t18 to <4 x i32> + ret <4 x i32> %t19 +} diff --git a/test/Transforms/InstCombine/2013-03-05-Combine-BitcastTy-Into-Alloca.ll b/test/Transforms/InstCombine/2013-03-05-Combine-BitcastTy-Into-Alloca.ll new file mode 100644 index 0000000000000..b20c3a07c0ac6 --- /dev/null +++ b/test/Transforms/InstCombine/2013-03-05-Combine-BitcastTy-Into-Alloca.ll @@ -0,0 +1,45 @@ +; RUN: opt < %s -instcombine -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-apple-macosx10.9.0" + +%struct._my_struct = type <{ [12 x i8], [4 x i8] }> + +@initval = common global %struct._my_struct zeroinitializer, align 1 + +; InstCombine will try to change the %struct._my_struct alloca into an +; allocation of an i96 because of the bitcast to create %2. That's not valid, +; as the other 32 bits of the structure still feed into the return value +define { i64, i64 } @function(i32 %x, i32 %y, i32 %z) nounwind { +; CHECK: @function +; CHECK-NEXT: entry: +; CHECK-NEXT: %retval = alloca %struct._my_struct, align 8 +; CHECK-NOT: bitcast i96* %retval to %struct._my_struct* +entry: + %retval = alloca %struct._my_struct, align 8 + %k.sroa.0.0.copyload = load i96* bitcast (%struct._my_struct* @initval to i96*), align 1 + %k.sroa.1.12.copyload = load i32* bitcast ([4 x i8]* getelementptr inbounds (%struct._my_struct* @initval, i64 0, i32 1) to i32*), align 1 + %0 = zext i32 %x to i96 + %bf.value = shl nuw nsw i96 %0, 6 + %bf.clear = and i96 %k.sroa.0.0.copyload, -288230376151711744 + %1 = zext i32 %y to i96 + %bf.value2 = shl nuw nsw i96 %1, 32 + %bf.shl3 = and i96 %bf.value2, 288230371856744448 + %bf.value.masked = and i96 %bf.value, 4294967232 + %2 = zext i32 %z to i96 + %bf.value8 = and i96 %2, 63 + %bf.clear4 = or i96 %bf.shl3, %bf.value.masked + %bf.set5 = or i96 %bf.clear4, %bf.value8 + %bf.set10 = or i96 %bf.set5, %bf.clear + %retval.0.cast7 = bitcast %struct._my_struct* %retval to i96* + store i96 %bf.set10, i96* %retval.0.cast7, align 8 + %retval.12.idx8 = getelementptr inbounds %struct._my_struct* %retval, i64 0, i32 1 + %retval.12.cast9 = bitcast [4 x i8]* %retval.12.idx8 to i32* + store i32 %k.sroa.1.12.copyload, i32* %retval.12.cast9, align 4 + %trunc = trunc i96 %bf.set10 to i64 + %.fca.0.insert = insertvalue { i64, i64 } undef, i64 %trunc, 0 + %retval.8.idx12 = getelementptr inbounds %struct._my_struct* %retval, i64 0, i32 0, i64 8 + %retval.8.cast13 = bitcast i8* %retval.8.idx12 to i64* + %retval.8.load14 = load i64* %retval.8.cast13, align 8 + %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %retval.8.load14, 1 + ret { i64, i64 } %.fca.1.insert +} diff --git a/test/Transforms/InstCombine/abs-1.ll b/test/Transforms/InstCombine/abs-1.ll new file mode 100644 index 0000000000000..807f238755b5d --- /dev/null +++ b/test/Transforms/InstCombine/abs-1.ll @@ -0,0 +1,41 @@ +; Test that the abs library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare i32 @abs(i32) +declare i64 @labs(i64) +declare i64 @llabs(i64) + +; Check abs(x) -> x >s -1 ? x : -x. + +define i32 @test_simplify1(i32 %x) { +; CHECK: @test_simplify1 + %ret = call i32 @abs(i32 %x) +; CHECK-NEXT: [[ISPOS:%[a-z0-9]+]] = icmp sgt i32 %x, -1 +; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub i32 0, %x +; CHECK-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[ISPOS]], i32 %x, i32 [[NEG]] + ret i32 %ret +; CHECK-NEXT: ret i32 [[RET]] +} + +define i64 @test_simplify2(i64 %x) { +; CHECK: @test_simplify2 + %ret = call i64 @labs(i64 %x) +; CHECK-NEXT: [[ISPOS:%[a-z0-9]+]] = icmp sgt i64 %x, -1 +; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub i64 0, %x +; CHECK-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[ISPOS]], i64 %x, i64 [[NEG]] + ret i64 %ret +; CHECK-NEXT: ret i64 [[RET]] +} + +define i64 @test_simplify3(i64 %x) { +; CHECK: @test_simplify3 + %ret = call i64 @llabs(i64 %x) +; CHECK-NEXT: [[ISPOS:%[a-z0-9]+]] = icmp sgt i64 %x, -1 +; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub i64 0, %x +; CHECK-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[ISPOS]], i64 %x, i64 [[NEG]] + ret i64 %ret +; CHECK-NEXT: ret i64 [[RET]] +} diff --git a/test/Transforms/InstCombine/align-external.ll b/test/Transforms/InstCombine/align-external.ll index d4a5d429912bf..c3ef2dbb70f03 100644 --- a/test/Transforms/InstCombine/align-external.ll +++ b/test/Transforms/InstCombine/align-external.ll @@ -8,7 +8,7 @@ ; CHECK: %q = add i64 %r, 1 ; CHECK: ret i64 %q -target datalayout = "-i32:8:32" +target datalayout = "i32:8:32" @A = external global i32 @B = weak_odr global i32 0 diff --git a/test/Transforms/InstCombine/bitcast-bigendian.ll b/test/Transforms/InstCombine/bitcast-bigendian.ll new file mode 100644 index 0000000000000..4ded581a14c6b --- /dev/null +++ b/test/Transforms/InstCombine/bitcast-bigendian.ll @@ -0,0 +1,50 @@ +; RUN: opt < %s -instcombine -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-f128:128:128-v128:128:128-n32:64" +target triple = "powerpc64-unknown-linux-gnu" + +; These tests are extracted from bitcast.ll. +; Verify that they also work correctly on big-endian targets. + +define float @test2(<2 x float> %A, <2 x i32> %B) { + %tmp28 = bitcast <2 x float> %A to i64 ; <i64> [#uses=2] + %tmp23 = trunc i64 %tmp28 to i32 ; <i32> [#uses=1] + %tmp24 = bitcast i32 %tmp23 to float ; <float> [#uses=1] + + %tmp = bitcast <2 x i32> %B to i64 + %tmp2 = trunc i64 %tmp to i32 ; <i32> [#uses=1] + %tmp4 = bitcast i32 %tmp2 to float ; <float> [#uses=1] + + %add = fadd float %tmp24, %tmp4 + ret float %add + +; CHECK: @test2 +; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 1 +; CHECK-NEXT: bitcast <2 x i32> %B to <2 x float> +; CHECK-NEXT: %tmp4 = extractelement <2 x float> {{.*}}, i32 1 +; CHECK-NEXT: %add = fadd float %tmp24, %tmp4 +; CHECK-NEXT: ret float %add +} + +define float @test3(<2 x float> %A, <2 x i64> %B) { + %tmp28 = bitcast <2 x float> %A to i64 + %tmp29 = lshr i64 %tmp28, 32 + %tmp23 = trunc i64 %tmp29 to i32 + %tmp24 = bitcast i32 %tmp23 to float + + %tmp = bitcast <2 x i64> %B to i128 + %tmp1 = lshr i128 %tmp, 64 + %tmp2 = trunc i128 %tmp1 to i32 + %tmp4 = bitcast i32 %tmp2 to float + + %add = fadd float %tmp24, %tmp4 + ret float %add + +; CHECK: @test3 +; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 0 +; CHECK-NEXT: bitcast <2 x i64> %B to <4 x float> +; CHECK-NEXT: %tmp4 = extractelement <4 x float> {{.*}}, i32 1 +; CHECK-NEXT: %add = fadd float %tmp24, %tmp4 +; CHECK-NEXT: ret float %add +} + diff --git a/test/Transforms/InstCombine/bitcast-vector-fold.ll b/test/Transforms/InstCombine/bitcast-vector-fold.ll index 8feec229171af..8fd7f35b7bb72 100644 --- a/test/Transforms/InstCombine/bitcast-vector-fold.ll +++ b/test/Transforms/InstCombine/bitcast-vector-fold.ll @@ -31,3 +31,8 @@ define <4 x i32> @test6() { %tmp3 = bitcast <2 x double> <double 0.5, double 1.0> to <4 x i32> ret <4 x i32> %tmp3 } + +define i32 @test7() { + %tmp3 = bitcast <2 x half> <half 0xH1100, half 0xH0011> to i32 + ret i32 %tmp3 +}
\ No newline at end of file diff --git a/test/Transforms/InstCombine/bitcast.ll b/test/Transforms/InstCombine/bitcast.ll index 8f6ae7d83527e..1e6113256bf36 100644 --- a/test/Transforms/InstCombine/bitcast.ll +++ b/test/Transforms/InstCombine/bitcast.ll @@ -11,7 +11,7 @@ define i32 @test1(i64 %a) { %t3 = xor <2 x i32> %t1, %t2 %t4 = extractelement <2 x i32> %t3, i32 0 ret i32 %t4 - + ; CHECK: @test1 ; CHECK: ret i32 0 } @@ -30,7 +30,7 @@ define float @test2(<2 x float> %A, <2 x i32> %B) { %add = fadd float %tmp24, %tmp4 ret float %add - + ; CHECK: @test2 ; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 0 ; CHECK-NEXT: bitcast <2 x i32> %B to <2 x float> @@ -55,7 +55,7 @@ define float @test3(<2 x float> %A, <2 x i64> %B) { %add = fadd float %tmp24, %tmp4 ret float %add - + ; CHECK: @test3 ; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 1 ; CHECK-NEXT: bitcast <2 x i64> %B to <4 x float> @@ -75,7 +75,7 @@ define <2 x i32> @test4(i32 %A, i32 %B){ ; CHECK: @test4 ; CHECK-NEXT: insertelement <2 x i32> undef, i32 %A, i32 0 ; CHECK-NEXT: insertelement <2 x i32> {{.*}}, i32 %B, i32 1 - ; CHECK-NEXT: ret <2 x i32> + ; CHECK-NEXT: ret <2 x i32> } @@ -92,7 +92,7 @@ define <2 x float> @test5(float %A, float %B) { ; CHECK: @test5 ; CHECK-NEXT: insertelement <2 x float> undef, float %A, i32 0 ; CHECK-NEXT: insertelement <2 x float> {{.*}}, float %B, i32 1 - ; CHECK-NEXT: ret <2 x float> + ; CHECK-NEXT: ret <2 x float> } define <2 x float> @test6(float %A){ @@ -123,7 +123,7 @@ define i64 @Vec2(i64 %in) { } define i64 @All11(i64 %in) { - %out = and i64 %in, xor (i64 bitcast (<2 x float> bitcast (i64 -1 to <2 x float>) to i64), i64 -1) + %out = and i64 %in, xor (i64 bitcast (<2 x float> bitcast (i64 -1 to <2 x float>) to i64), i64 -1) ret i64 %out ; CHECK: @All11 ; CHECK: ret i64 0 @@ -131,9 +131,16 @@ define i64 @All11(i64 %in) { define i32 @All111(i32 %in) { - %out = and i32 %in, xor (i32 bitcast (<1 x float> bitcast (i32 -1 to <1 x float>) to i32), i32 -1) + %out = and i32 %in, xor (i32 bitcast (<1 x float> bitcast (i32 -1 to <1 x float>) to i32), i32 -1) ret i32 %out ; CHECK: @All111 ; CHECK: ret i32 0 } +define <2 x i16> @BitcastInsert(i32 %a) { + %v = insertelement <1 x i32> undef, i32 %a, i32 0 + %r = bitcast <1 x i32> %v to <2 x i16> + ret <2 x i16> %r +; CHECK: @BitcastInsert +; CHECK: bitcast i32 %a to <2 x i16> +} diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll index b4eb69d4363dd..de738bb7c06d7 100644 --- a/test/Transforms/InstCombine/cast.ll +++ b/test/Transforms/InstCombine/cast.ll @@ -473,14 +473,12 @@ define i64 @test51(i64 %A, i1 %cond) { %F = sext i32 %E to i64 ret i64 %F ; CHECK: @test51 - -; FIXME: disabled, see PR5997 -; HECK-NEXT: %C = and i64 %A, 4294967294 -; HECK-NEXT: %D = or i64 %A, 1 -; HECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D -; HECK-NEXT: %sext = shl i64 %E, 32 -; HECK-NEXT: %F = ashr i64 %sext, 32 -; HECK-NEXT: ret i64 %F +; CHECK-NEXT: %C = and i64 %A, 4294967294 +; CHECK-NEXT: %D = or i64 %A, 1 +; CHECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D +; CHECK-NEXT: %sext = shl i64 %E, 32 +; CHECK-NEXT: %F = ashr exact i64 %sext, 32 +; CHECK-NEXT: ret i64 %F } define i32 @test52(i64 %A) { diff --git a/test/Transforms/InstCombine/compare-signs.ll b/test/Transforms/InstCombine/compare-signs.ll index f8e49110610a2..72db66e3ab0f6 100644 --- a/test/Transforms/InstCombine/compare-signs.ll +++ b/test/Transforms/InstCombine/compare-signs.ll @@ -1,4 +1,4 @@ -; RUN: opt %s -instcombine -S | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s ; PR5438 ; TODO: This should also optimize down. diff --git a/test/Transforms/InstCombine/constant-expr-datalayout.ll b/test/Transforms/InstCombine/constant-expr-datalayout.ll new file mode 100644 index 0000000000000..9a72c77afdb0f --- /dev/null +++ b/test/Transforms/InstCombine/constant-expr-datalayout.ll @@ -0,0 +1,12 @@ +; RUN: opt -instcombine %s -S -o - | 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" + +%test1.struct = type { i32, i32 } +@test1.aligned_glbl = global %test1.struct zeroinitializer, align 4 +define void @test1(i64 *%ptr) { + store i64 and (i64 ptrtoint (i32* getelementptr (%test1.struct* @test1.aligned_glbl, i32 0, i32 1) to i64), i64 3), i64* %ptr +; CHECK: store i64 0, i64* %ptr + ret void +} diff --git a/test/Transforms/InstCombine/cos-1.ll b/test/Transforms/InstCombine/cos-1.ll new file mode 100644 index 0000000000000..b92e448abd9f9 --- /dev/null +++ b/test/Transforms/InstCombine/cos-1.ll @@ -0,0 +1,38 @@ +; Test that the cos library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s -check-prefix=NO-FLOAT-SHRINK +; RUN: opt < %s -instcombine -enable-double-float-shrink -S | FileCheck %s -check-prefix=DO-FLOAT-SHRINK + +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" + +declare double @cos(double) + +; Check cos(-x) -> cos(x); + +define double @test_simplify1(double %d) { +; NO-FLOAT-SHRINK: @test_simplify1 + %neg = fsub double -0.000000e+00, %d + %cos = call double @cos(double %neg) +; NO-FLOAT-SHRINK: call double @cos(double %d) + ret double %cos +} + +define float @test_simplify2(float %f) { +; DO-FLOAT-SHRINK: @test_simplify2 + %conv1 = fpext float %f to double + %neg = fsub double -0.000000e+00, %conv1 + %cos = call double @cos(double %neg) + %conv2 = fptrunc double %cos to float +; DO-FLOAT-SHRINK: call float @cosf(float %f) + ret float %conv2 +} + +define float @test_simplify3(float %f) { +; NO-FLOAT-SHRINK: @test_simplify3 + %conv1 = fpext float %f to double + %neg = fsub double -0.000000e+00, %conv1 + %cos = call double @cos(double %neg) +; NO-FLOAT-SHRINK: call double @cos(double %conv1) + %conv2 = fptrunc double %cos to float + ret float %conv2 +} diff --git a/test/Transforms/InstCombine/cos-2.ll b/test/Transforms/InstCombine/cos-2.ll new file mode 100644 index 0000000000000..2f2dfafe484d5 --- /dev/null +++ b/test/Transforms/InstCombine/cos-2.ll @@ -0,0 +1,17 @@ +; Test that the cos library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -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" + +declare float @cos(double) + +; Check that cos functions with the wrong prototype aren't simplified. + +define float @test_no_simplify1(double %d) { +; CHECK: @test_no_simplify1 + %neg = fsub double -0.000000e+00, %d + %cos = call float @cos(double %neg) +; CHECK: call float @cos(double %neg) + ret float %cos +} diff --git a/test/Transforms/InstCombine/debug-line.ll b/test/Transforms/InstCombine/debug-line.ll new file mode 100644 index 0000000000000..084efdc989f93 --- /dev/null +++ b/test/Transforms/InstCombine/debug-line.ll @@ -0,0 +1,24 @@ +; RUN: opt -instcombine -S < %s | FileCheck %s + + +@.str = private constant [3 x i8] c"%c\00" + +define void @foo() nounwind ssp { +;CHECK: call i32 @putchar{{.+}} !dbg + %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i32 97), !dbg !5 + ret void, !dbg !7 +} + +declare i32 @printf(i8*, ...) + +!llvm.dbg.sp = !{!0} + +!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"", metadata !1, i32 4, metadata !3, i1 false, i1 true, i32 0, i32 0, null, i32 0, i1 false, void ()* @foo} ; [ DW_TAG_subprogram ] +!1 = metadata !{i32 589865, metadata !"m.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ] +!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"m.c", metadata !"/private/tmp", metadata !"clang", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ] +!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0, null} ; [ DW_TAG_subroutine_type ] +!4 = metadata !{null} +!5 = metadata !{i32 5, i32 2, metadata !6, null} +!6 = metadata !{i32 589835, metadata !0, i32 4, i32 12, metadata !1, i32 0} ; [ DW_TAG_lexical_block ] +!7 = metadata !{i32 6, i32 1, metadata !6, null} + diff --git a/test/Transforms/InstCombine/debuginfo.ll b/test/Transforms/InstCombine/debuginfo.ll index f6892fc3e1f9c..cdbcd865117cf 100644 --- a/test/Transforms/InstCombine/debuginfo.ll +++ b/test/Transforms/InstCombine/debuginfo.ll @@ -28,22 +28,21 @@ entry: ret i8* %call, !dbg !21 } -!llvm.dbg.lv.foobar = !{!0, !7, !9} -!llvm.dbg.sp = !{!1} +!llvm.dbg.cu = !{!3} -!0 = metadata !{i32 590081, metadata !1, metadata !"__dest", metadata !2, i32 16777294, metadata !6, i32 0} ; [ DW_TAG_arg_variable ] -!1 = metadata !{i32 589870, i32 0, metadata !2, metadata !"foobar", metadata !"foobar", metadata !"", metadata !2, i32 79, metadata !4, i1 true, i1 true, i32 0, i32 0, i32 0, i32 256, i1 true, i8* (i8*, i32, i64)* @foobar} ; [ DW_TAG_subprogram ] -!2 = metadata !{i32 589865, metadata !"string.h", metadata !"Game", metadata !3} ; [ DW_TAG_file_type ] -!3 = metadata !{i32 589841, i32 0, i32 12, metadata !"bits.c", metadata !"Game", metadata !"clang version 3.0 (trunk 127710)", i1 true, i1 true, metadata !"", i32 0} ; [ DW_TAG_compile_unit ] -!4 = metadata !{i32 589845, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !5, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] +!0 = metadata !{i32 786689, metadata !1, metadata !"__dest", metadata !2, i32 16777294, metadata !6, i32 0, null} ; [ DW_TAG_arg_variable ] +!1 = metadata !{i32 786478, metadata !2, metadata !"foobar", metadata !"foobar", metadata !"", metadata !2, i32 79, metadata !4, i1 true, i1 true, i32 0, i32 0, i32 0, i32 256, i1 true, i8* (i8*, i32, i64)* @foobar, null, null, metadata !25, i32 79} ; [ DW_TAG_subprogram ] +!2 = metadata !{i32 786473, metadata !27} ; [ DW_TAG_file_type ] +!3 = metadata !{i32 786449, i32 0, i32 12, metadata !26, metadata !"clang version 3.0 (trunk 127710)", i1 true, metadata !"", i32 0, null, null, metadata !24, null, null} ; [ DW_TAG_compile_unit ] +!4 = metadata !{i32 786453, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !5, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] !5 = metadata !{metadata !6} -!6 = metadata !{i32 589839, metadata !3, metadata !"", null, i32 0, i64 64, i64 64, i64 0, i32 0, null} ; [ DW_TAG_pointer_type ] -!7 = metadata !{i32 590081, metadata !1, metadata !"__val", metadata !2, i32 33554510, metadata !8, i32 0} ; [ DW_TAG_arg_variable ] -!8 = metadata !{i32 589860, metadata !3, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] -!9 = metadata !{i32 590081, metadata !1, metadata !"__len", metadata !2, i32 50331726, metadata !10, i32 0} ; [ DW_TAG_arg_variable ] +!6 = metadata !{i32 786447, metadata !3, metadata !"", null, i32 0, i64 64, i64 64, i64 0, i32 0, null} ; [ DW_TAG_pointer_type ] +!7 = metadata !{i32 786689, metadata !1, metadata !"__val", metadata !2, i32 33554510, metadata !8, i32 0, null} ; [ DW_TAG_arg_variable ] +!8 = metadata !{i32 786468, metadata !3, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] +!9 = metadata !{i32 786689, metadata !1, metadata !"__len", metadata !2, i32 50331726, metadata !10, i32 0, null} ; [ DW_TAG_arg_variable ] !10 = metadata !{i32 589846, metadata !3, metadata !"size_t", metadata !2, i32 80, i64 0, i64 0, i64 0, i32 0, metadata !11} ; [ DW_TAG_typedef ] !11 = metadata !{i32 589846, metadata !3, metadata !"__darwin_size_t", metadata !2, i32 90, i64 0, i64 0, i64 0, i32 0, metadata !12} ; [ DW_TAG_typedef ] -!12 = metadata !{i32 589860, metadata !3, metadata !"long unsigned int", null, i32 0, i64 64, i64 64, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ] +!12 = metadata !{i32 786468, metadata !3, metadata !"long unsigned int", null, i32 0, i64 64, i64 64, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ] !13 = metadata !{metadata !"any pointer", metadata !14} !14 = metadata !{metadata !"omnipotent char", metadata !15} !15 = metadata !{metadata !"Simple C/C++ TBAA", null} @@ -53,5 +52,10 @@ entry: !19 = metadata !{metadata !"long", metadata !14} !20 = metadata !{i32 78, i32 54, metadata !1, null} !21 = metadata !{i32 80, i32 3, metadata !22, null} -!22 = metadata !{i32 589835, metadata !23, i32 80, i32 3, metadata !2, i32 7} ; [ DW_TAG_lexical_block ] -!23 = metadata !{i32 589835, metadata !1, i32 79, i32 1, metadata !2, i32 6} ; [ DW_TAG_lexical_block ] +!22 = metadata !{i32 786443, metadata !23, i32 80, i32 3, metadata !2, i32 7} ; [ DW_TAG_lexical_block ] +!23 = metadata !{i32 786443, metadata !1, i32 79, i32 1, metadata !2, i32 6} ; [ DW_TAG_lexical_block ] +!24 = metadata !{metadata !1} +!25 = metadata !{metadata !0, metadata !7, metadata !9} +!26 = metadata !{i32 786473, metadata !28} ; [ DW_TAG_file_type ] +!27 = metadata !{metadata !"string.h", metadata !"Game"} +!28 = metadata !{metadata !"bits.c", metadata !"Game"} diff --git a/test/Transforms/InstCombine/devirt.ll b/test/Transforms/InstCombine/devirt.ll index 6189dc2af4f94..9c7cf5d697e84 100644 --- a/test/Transforms/InstCombine/devirt.ll +++ b/test/Transforms/InstCombine/devirt.ll @@ -1,4 +1,4 @@ -; RUN: opt -instcombine -S -o - %s | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s ; CHECK-NOT: getelementptr ; CHECK-NOT: ptrtoint diff --git a/test/Transforms/InstCombine/disable-simplify-libcalls.ll b/test/Transforms/InstCombine/disable-simplify-libcalls.ll index d81e9ae5bd732..c2c29368b1a8a 100644 --- a/test/Transforms/InstCombine/disable-simplify-libcalls.ll +++ b/test/Transforms/InstCombine/disable-simplify-libcalls.ll @@ -37,6 +37,18 @@ declare i64 @strtoll(i8*, i8**, i32) declare i64 @strtoul(i8*, i8**, i32) declare i64 @strtoull(i8*, i8**, i32) declare i64 @strcspn(i8*, i8*) +declare i32 @abs(i32) +declare i32 @ffs(i32) +declare i32 @ffsl(i64) +declare i32 @ffsll(i64) +declare i32 @fprintf(i8*, i8*) +declare i32 @isascii(i32) +declare i32 @isdigit(i32) +declare i32 @toascii(i32) +declare i64 @labs(i64) +declare i64 @llabs(i64) +declare i32 @printf(i8*) +declare i32 @sprintf(i8*, i8*) define double @t1(double %x) { ; CHECK: @t1 @@ -234,3 +246,90 @@ define i64 @t25(i8* %y) { ret i64 %ret ; CHECK: call i64 @strcspn } + +define i32 @t26(i32 %y) { +; CHECK: @t26 + %ret = call i32 @abs(i32 %y) + ret i32 %ret +; CHECK: call i32 @abs +} + +define i32 @t27(i32 %y) { +; CHECK: @t27 + %ret = call i32 @ffs(i32 %y) + ret i32 %ret +; CHECK: call i32 @ffs +} + +define i32 @t28(i64 %y) { +; CHECK: @t28 + %ret = call i32 @ffsl(i64 %y) + ret i32 %ret +; CHECK: call i32 @ffsl +} + +define i32 @t29(i64 %y) { +; CHECK: @t29 + %ret = call i32 @ffsll(i64 %y) + ret i32 %ret +; CHECK: call i32 @ffsll +} + +define void @t30() { +; CHECK: @t30 + %x = getelementptr inbounds [13 x i8]* @.str1, i32 0, i32 0 + call i32 @fprintf(i8* null, i8* %x) + ret void +; CHECK: call i32 @fprintf +} + +define i32 @t31(i32 %y) { +; CHECK: @t31 + %ret = call i32 @isascii(i32 %y) + ret i32 %ret +; CHECK: call i32 @isascii +} + +define i32 @t32(i32 %y) { +; CHECK: @t32 + %ret = call i32 @isdigit(i32 %y) + ret i32 %ret +; CHECK: call i32 @isdigit +} + +define i32 @t33(i32 %y) { +; CHECK: @t33 + %ret = call i32 @toascii(i32 %y) + ret i32 %ret +; CHECK: call i32 @toascii +} + +define i64 @t34(i64 %y) { +; CHECK: @t34 + %ret = call i64 @labs(i64 %y) + ret i64 %ret +; CHECK: call i64 @labs +} + +define i64 @t35(i64 %y) { +; CHECK: @t35 + %ret = call i64 @llabs(i64 %y) + ret i64 %ret +; CHECK: call i64 @llabs +} + +define void @t36() { +; CHECK: @t36 + %x = getelementptr inbounds [1 x i8]* @empty, i32 0, i32 0 + call i32 @printf(i8* %x) + ret void +; CHECK: call i32 @printf +} + +define void @t37(i8* %x) { +; CHECK: @t37 + %y = getelementptr inbounds [13 x i8]* @.str1, i32 0, i32 0 + call i32 @sprintf(i8* %x, i8* %y) + ret void +; CHECK: call i32 @sprintf +} diff --git a/test/Transforms/InstCombine/double-float-shrink-1.ll b/test/Transforms/InstCombine/double-float-shrink-1.ll new file mode 100644 index 0000000000000..e5448ee007654 --- /dev/null +++ b/test/Transforms/InstCombine/double-float-shrink-1.ll @@ -0,0 +1,333 @@ +; RUN: opt < %s -instcombine -enable-double-float-shrink -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 float @acos_test(float %f) nounwind readnone { +; CHECK: acos_test + %conv = fpext float %f to double + %call = call double @acos(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @acosf(float %f) +} + +define double @acos_test2(float %f) nounwind readnone { +; CHECK: acos_test2 + %conv = fpext float %f to double + %call = call double @acos(double %conv) + ret double %call +; CHECK: call double @acos(double %conv) +} + +define float @acosh_test(float %f) nounwind readnone { +; CHECK: acosh_test + %conv = fpext float %f to double + %call = call double @acosh(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @acoshf(float %f) +} + +define double @acosh_test2(float %f) nounwind readnone { +; CHECK: acosh_test2 + %conv = fpext float %f to double + %call = call double @acosh(double %conv) + ret double %call +; CHECK: call double @acosh(double %conv) +} + +define float @asin_test(float %f) nounwind readnone { +; CHECK: asin_test + %conv = fpext float %f to double + %call = call double @asin(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @asinf(float %f) +} + +define double @asin_test2(float %f) nounwind readnone { +; CHECK: asin_test2 + %conv = fpext float %f to double + %call = call double @asin(double %conv) + ret double %call +; CHECK: call double @asin(double %conv) +} + +define float @asinh_test(float %f) nounwind readnone { +; CHECK: asinh_test + %conv = fpext float %f to double + %call = call double @asinh(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @asinhf(float %f) +} + +define double @asinh_test2(float %f) nounwind readnone { +; CHECK: asinh_test2 + %conv = fpext float %f to double + %call = call double @asinh(double %conv) + ret double %call +; CHECK: call double @asinh(double %conv) +} + +define float @atan_test(float %f) nounwind readnone { +; CHECK: atan_test + %conv = fpext float %f to double + %call = call double @atan(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @atanf(float %f) +} + +define double @atan_test2(float %f) nounwind readnone { +; CHECK: atan_test2 + %conv = fpext float %f to double + %call = call double @atan(double %conv) + ret double %call +; CHECK: call double @atan(double %conv) +} +define float @atanh_test(float %f) nounwind readnone { +; CHECK: atanh_test + %conv = fpext float %f to double + %call = call double @atanh(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @atanhf(float %f) +} + +define double @atanh_test2(float %f) nounwind readnone { +; CHECK: atanh_test2 + %conv = fpext float %f to double + %call = call double @atanh(double %conv) + ret double %call +; CHECK: call double @atanh(double %conv) +} +define float @cbrt_test(float %f) nounwind readnone { +; CHECK: cbrt_test + %conv = fpext float %f to double + %call = call double @cbrt(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @cbrtf(float %f) +} + +define double @cbrt_test2(float %f) nounwind readnone { +; CHECK: cbrt_test2 + %conv = fpext float %f to double + %call = call double @cbrt(double %conv) + ret double %call +; CHECK: call double @cbrt(double %conv) +} +define float @exp_test(float %f) nounwind readnone { +; CHECK: exp_test + %conv = fpext float %f to double + %call = call double @exp(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @expf(float %f) +} + +define double @exp_test2(float %f) nounwind readnone { +; CHECK: exp_test2 + %conv = fpext float %f to double + %call = call double @exp(double %conv) + ret double %call +; CHECK: call double @exp(double %conv) +} +define float @expm1_test(float %f) nounwind readnone { +; CHECK: expm1_test + %conv = fpext float %f to double + %call = call double @expm1(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @expm1f(float %f) +} + +define double @expm1_test2(float %f) nounwind readnone { +; CHECK: expm1_test2 + %conv = fpext float %f to double + %call = call double @expm1(double %conv) + ret double %call +; CHECK: call double @expm1(double %conv) +} +define float @exp10_test(float %f) nounwind readnone { +; CHECK: exp10_test + %conv = fpext float %f to double + %call = call double @exp10(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @exp10f(float %f) +} + +define double @exp10_test2(float %f) nounwind readnone { +; CHECK: exp10_test2 + %conv = fpext float %f to double + %call = call double @exp10(double %conv) + ret double %call +; CHECK: call double @exp10(double %conv) +} +define float @log_test(float %f) nounwind readnone { +; CHECK: log_test + %conv = fpext float %f to double + %call = call double @log(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @logf(float %f) +} + +define double @log_test2(float %f) nounwind readnone { +; CHECK: log_test2 + %conv = fpext float %f to double + %call = call double @log(double %conv) + ret double %call +; CHECK: call double @log(double %conv) +} +define float @log10_test(float %f) nounwind readnone { +; CHECK: log10_test + %conv = fpext float %f to double + %call = call double @log10(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @log10f(float %f) +} + +define double @log10_test2(float %f) nounwind readnone { +; CHECK: log10_test2 + %conv = fpext float %f to double + %call = call double @log10(double %conv) + ret double %call +; CHECK: call double @log10(double %conv) +} +define float @log1p_test(float %f) nounwind readnone { +; CHECK: log1p_test + %conv = fpext float %f to double + %call = call double @log1p(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @log1pf(float %f) +} + +define double @log1p_test2(float %f) nounwind readnone { +; CHECK: log1p_test2 + %conv = fpext float %f to double + %call = call double @log1p(double %conv) + ret double %call +; CHECK: call double @log1p(double %conv) +} +define float @log2_test(float %f) nounwind readnone { +; CHECK: log2_test + %conv = fpext float %f to double + %call = call double @log2(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @log2f(float %f) +} + +define double @log2_test2(float %f) nounwind readnone { +; CHECK: log2_test2 + %conv = fpext float %f to double + %call = call double @log2(double %conv) + ret double %call +; CHECK: call double @log2(double %conv) +} +define float @logb_test(float %f) nounwind readnone { +; CHECK: logb_test + %conv = fpext float %f to double + %call = call double @logb(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @logbf(float %f) +} + +define double @logb_test2(float %f) nounwind readnone { +; CHECK: logb_test2 + %conv = fpext float %f to double + %call = call double @logb(double %conv) + ret double %call +; CHECK: call double @logb(double %conv) +} +define float @sin_test(float %f) nounwind readnone { +; CHECK: sin_test + %conv = fpext float %f to double + %call = call double @sin(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @sinf(float %f) +} + +define double @sin_test2(float %f) nounwind readnone { +; CHECK: sin_test2 + %conv = fpext float %f to double + %call = call double @sin(double %conv) + ret double %call +; CHECK: call double @sin(double %conv) +} +define float @sqrt_test(float %f) nounwind readnone { +; CHECK: sqrt_test + %conv = fpext float %f to double + %call = call double @sqrt(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @sqrtf(float %f) +} + +define double @sqrt_test2(float %f) nounwind readnone { +; CHECK: sqrt_test2 + %conv = fpext float %f to double + %call = call double @sqrt(double %conv) + ret double %call +; CHECK: call double @sqrt(double %conv) +} +define float @tan_test(float %f) nounwind readnone { +; CHECK: tan_test + %conv = fpext float %f to double + %call = call double @tan(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @tanf(float %f) +} + +define double @tan_test2(float %f) nounwind readnone { +; CHECK: tan_test2 + %conv = fpext float %f to double + %call = call double @tan(double %conv) + ret double %call +; CHECK: call double @tan(double %conv) +} +define float @tanh_test(float %f) nounwind readnone { +; CHECK: tanh_test + %conv = fpext float %f to double + %call = call double @tanh(double %conv) + %conv1 = fptrunc double %call to float + ret float %conv1 +; CHECK: call float @tanhf(float %f) +} + +define double @tanh_test2(float %f) nounwind readnone { +; CHECK: tanh_test2 + %conv = fpext float %f to double + %call = call double @tanh(double %conv) + ret double %call +; CHECK: call double @tanh(double %conv) +} + +declare double @tanh(double) nounwind readnone +declare double @tan(double) nounwind readnone +declare double @sqrt(double) nounwind readnone +declare double @sin(double) nounwind readnone +declare double @log2(double) nounwind readnone +declare double @log1p(double) nounwind readnone +declare double @log10(double) nounwind readnone +declare double @log(double) nounwind readnone +declare double @logb(double) nounwind readnone +declare double @exp10(double) nounwind readnone +declare double @expm1(double) nounwind readnone +declare double @exp(double) nounwind readnone +declare double @cbrt(double) nounwind readnone +declare double @atanh(double) nounwind readnone +declare double @atan(double) nounwind readnone +declare double @acos(double) nounwind readnone +declare double @acosh(double) nounwind readnone +declare double @asin(double) nounwind readnone +declare double @asinh(double) nounwind readnone diff --git a/test/Transforms/InstCombine/double-float-shrink-2.ll b/test/Transforms/InstCombine/double-float-shrink-2.ll new file mode 100644 index 0000000000000..7f6df92c96c5a --- /dev/null +++ b/test/Transforms/InstCombine/double-float-shrink-2.ll @@ -0,0 +1,80 @@ +; RUN: opt < %s -instcombine -S -mtriple "i386-pc-linux" | FileCheck -check-prefix=DO-SIMPLIFY %s +; RUN: opt < %s -instcombine -S -mtriple "i386-pc-win32" | FileCheck -check-prefix=DONT-SIMPLIFY %s +; RUN: opt < %s -instcombine -S -mtriple "x86_64-pc-win32" | FileCheck -check-prefix=C89-SIMPLIFY %s +; RUN: opt < %s -instcombine -S -mtriple "i386-pc-mingw32" | FileCheck -check-prefix=DO-SIMPLIFY %s +; RUN: opt < %s -instcombine -S -mtriple "x86_64-pc-mingw32" | FileCheck -check-prefix=DO-SIMPLIFY %s +; RUN: opt < %s -instcombine -S -mtriple "sparc-sun-solaris" | FileCheck -check-prefix=DO-SIMPLIFY %s + +; DO-SIMPLIFY: call float @floorf( +; DO-SIMPLIFY: call float @ceilf( +; DO-SIMPLIFY: call float @roundf( +; DO-SIMPLIFY: call float @nearbyintf( +; DO-SIMPLIFY: call float @truncf( +; DO-SIMPLIFY: call float @fabsf( + +; C89-SIMPLIFY: call float @floorf( +; C89-SIMPLIFY: call float @ceilf( +; C89-SIMPLIFY: call double @round( +; C89-SIMPLIFY: call double @nearbyint( + +; DONT-SIMPLIFY: call double @floor( +; DONT-SIMPLIFY: call double @ceil( +; DONT-SIMPLIFY: call double @round( +; DONT-SIMPLIFY: call double @nearbyint( +; DONT-SIMPLIFY: call double @trunc( +; DONT-SIMPLIFY: call double @fabs( + +declare double @floor(double) +declare double @ceil(double) +declare double @round(double) +declare double @nearbyint(double) +declare double @trunc(double) +declare double @fabs(double) + +define float @test_floor(float %C) { + %D = fpext float %C to double + ; --> floorf + %E = call double @floor(double %D) + %F = fptrunc double %E to float + ret float %F +} + +define float @test_ceil(float %C) { + %D = fpext float %C to double + ; --> ceilf + %E = call double @ceil(double %D) + %F = fptrunc double %E to float + ret float %F +} + +define float @test_round(float %C) { + %D = fpext float %C to double + ; --> roundf + %E = call double @round(double %D) + %F = fptrunc double %E to float + ret float %F +} + +define float @test_nearbyint(float %C) { + %D = fpext float %C to double + ; --> nearbyintf + %E = call double @nearbyint(double %D) + %F = fptrunc double %E to float + ret float %F +} + +define float @test_trunc(float %C) { + %D = fpext float %C to double + ; --> truncf + %E = call double @trunc(double %D) + %F = fptrunc double %E to float + ret float %F +} + +define float @test_fabs(float %C) { + %D = fpext float %C to double + ; --> fabsf + %E = call double @fabs(double %D) + %F = fptrunc double %E to float + ret float %F +} diff --git a/test/Transforms/InstCombine/exact.ll b/test/Transforms/InstCombine/exact.ll index 14741e3c1c336..88ca88c3b9275 100644 --- a/test/Transforms/InstCombine/exact.ll +++ b/test/Transforms/InstCombine/exact.ll @@ -99,9 +99,9 @@ define i1 @ashr_icmp2(i64 %X) nounwind { ; PR9998 ; Make sure we don't transform the ashr here into an sdiv ; CHECK: @pr9998 -; CHECK: = and i32 %V, 1 -; CHECK: %Z = icmp ne -; CHECK: ret i1 %Z +; CHECK: [[BIT:%[A-Za-z0-9.]+]] = and i32 %V, 1 +; CHECK-NEXT: [[CMP:%[A-Za-z0-9.]+]] = icmp ne i32 [[BIT]], 0 +; CHECK-NEXT: ret i1 [[CMP]] define i1 @pr9998(i32 %V) nounwind { entry: %W = shl i32 %V, 31 @@ -112,6 +112,7 @@ entry: } + ; CHECK: @udiv_icmp1 ; CHECK: icmp ne i64 %X, 0 define i1 @udiv_icmp1(i64 %X) nounwind { diff --git a/test/Transforms/InstCombine/exp2-1.ll b/test/Transforms/InstCombine/exp2-1.ll new file mode 100644 index 0000000000000..1b0ad5000412d --- /dev/null +++ b/test/Transforms/InstCombine/exp2-1.ll @@ -0,0 +1,76 @@ +; Test that the exp2 library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare double @exp2(double) +declare float @exp2f(float) + +; Check exp2(sitofp(x)) -> ldexp(1.0, sext(x)). + +define double @test_simplify1(i32 %x) { +; CHECK: @test_simplify1 + %conv = sitofp i32 %x to double + %ret = call double @exp2(double %conv) +; CHECK: call double @ldexp + ret double %ret +} + +define double @test_simplify2(i16 signext %x) { +; CHECK: @test_simplify2 + %conv = sitofp i16 %x to double + %ret = call double @exp2(double %conv) +; CHECK: call double @ldexp + ret double %ret +} + +define double @test_simplify3(i8 signext %x) { +; CHECK: @test_simplify3 + %conv = sitofp i8 %x to double + %ret = call double @exp2(double %conv) +; CHECK: call double @ldexp + ret double %ret +} + +define float @test_simplify4(i32 %x) { +; CHECK: @test_simplify4 + %conv = sitofp i32 %x to float + %ret = call float @exp2f(float %conv) +; CHECK: call float @ldexpf + ret float %ret +} + +; Check exp2(uitofp(x)) -> ldexp(1.0, zext(x)). + +define double @test_no_simplify1(i32 %x) { +; CHECK: @test_no_simplify1 + %conv = uitofp i32 %x to double + %ret = call double @exp2(double %conv) +; CHECK: call double @exp2 + ret double %ret +} + +define double @test_simplify6(i16 zeroext %x) { +; CHECK: @test_simplify6 + %conv = uitofp i16 %x to double + %ret = call double @exp2(double %conv) +; CHECK: call double @ldexp + ret double %ret +} + +define double @test_simplify7(i8 zeroext %x) { +; CHECK: @test_simplify7 + %conv = uitofp i8 %x to double + %ret = call double @exp2(double %conv) +; CHECK: call double @ldexp + ret double %ret +} + +define float @test_simplify8(i8 zeroext %x) { +; CHECK: @test_simplify8 + %conv = uitofp i8 %x to float + %ret = call float @exp2f(float %conv) +; CHECK: call float @ldexpf + ret float %ret +} diff --git a/test/Transforms/InstCombine/exp2-2.ll b/test/Transforms/InstCombine/exp2-2.ll new file mode 100644 index 0000000000000..bed063798e293 --- /dev/null +++ b/test/Transforms/InstCombine/exp2-2.ll @@ -0,0 +1,17 @@ +; Test that the exp2 library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare float @exp2(double) + +; Check that exp2 functions with the wrong prototype aren't simplified. + +define float @test_no_simplify1(i32 %x) { +; CHECK: @test_no_simplify1 + %conv = sitofp i32 %x to double + %ret = call float @exp2(double %conv) +; CHECK: call float @exp2(double %conv) + ret float %ret +} diff --git a/test/Transforms/InstCombine/fast-math.ll b/test/Transforms/InstCombine/fast-math.ll new file mode 100644 index 0000000000000..edcbcc71dfb48 --- /dev/null +++ b/test/Transforms/InstCombine/fast-math.ll @@ -0,0 +1,467 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +; testing-case "float fold(float a) { return 1.2f * a * 2.3f; }" +; 1.2f and 2.3f is supposed to be fold. +define float @fold(float %a) { + %mul = fmul fast float %a, 0x3FF3333340000000 + %mul1 = fmul fast float %mul, 0x4002666660000000 + ret float %mul1 +; CHECK: @fold +; CHECK: fmul fast float %a, 0x4006147AE0000000 +} + +; Same testing-case as the one used in fold() except that the operators have +; fixed FP mode. +define float @notfold(float %a) { +; CHECK: @notfold +; CHECK: %mul = fmul fast float %a, 0x3FF3333340000000 + %mul = fmul fast float %a, 0x3FF3333340000000 + %mul1 = fmul float %mul, 0x4002666660000000 + ret float %mul1 +} + +define float @fold2(float %a) { +; CHECK: @fold2 +; CHECK: fmul fast float %a, 0x4006147AE0000000 + %mul = fmul float %a, 0x3FF3333340000000 + %mul1 = fmul fast float %mul, 0x4002666660000000 + ret float %mul1 +} + +; C * f1 + f1 = (C+1) * f1 +define double @fold3(double %f1) { + %t1 = fmul fast double 2.000000e+00, %f1 + %t2 = fadd fast double %f1, %t1 + ret double %t2 +; CHECK: @fold3 +; CHECK: fmul fast double %f1, 3.000000e+00 +} + +; (C1 - X) + (C2 - Y) => (C1+C2) - (X + Y) +define float @fold4(float %f1, float %f2) { + %sub = fsub float 4.000000e+00, %f1 + %sub1 = fsub float 5.000000e+00, %f2 + %add = fadd fast float %sub, %sub1 + ret float %add +; CHECK: @fold4 +; CHECK: %1 = fadd fast float %f1, %f2 +; CHECK: fsub fast float 9.000000e+00, %1 +} + +; (X + C1) + C2 => X + (C1 + C2) +define float @fold5(float %f1, float %f2) { + %add = fadd float %f1, 4.000000e+00 + %add1 = fadd fast float %add, 5.000000e+00 + ret float %add1 +; CHECK: @fold5 +; CHECK: fadd fast float %f1, 9.000000e+00 +} + +; (X + X) + X => 3.0 * X +define float @fold6(float %f1) { + %t1 = fadd fast float %f1, %f1 + %t2 = fadd fast float %f1, %t1 + ret float %t2 +; CHECK: @fold6 +; CHECK: fmul fast float %f1, 3.000000e+00 +} + +; C1 * X + (X + X) = (C1 + 2) * X +define float @fold7(float %f1) { + %t1 = fmul fast float %f1, 5.000000e+00 + %t2 = fadd fast float %f1, %f1 + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: @fold7 +; CHECK: fmul fast float %f1, 7.000000e+00 +} + +; (X + X) + (X + X) => 4.0 * X +define float @fold8(float %f1) { + %t1 = fadd fast float %f1, %f1 + %t2 = fadd fast float %f1, %f1 + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: fold8 +; CHECK: fmul fast float %f1, 4.000000e+00 +} + +; X - (X + Y) => 0 - Y +define float @fold9(float %f1, float %f2) { + %t1 = fadd float %f1, %f2 + %t3 = fsub fast float %f1, %t1 + ret float %t3 + +; CHECK: @fold9 +; CHECK: fsub fast float 0.000000e+00, %f2 +} + +; Let C3 = C1 + C2. (f1 + C1) + (f2 + C2) => (f1 + f2) + C3 instead of +; "(f1 + C3) + f2" or "(f2 + C3) + f1". Placing constant-addend at the +; top of resulting simplified expression tree may potentially reveal some +; optimization opportunities in the super-expression trees. +; +define float @fold10(float %f1, float %f2) { + %t1 = fadd fast float 2.000000e+00, %f1 + %t2 = fsub fast float %f2, 3.000000e+00 + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: @fold10 +; CHECK: %t3 = fadd fast float %t2, -1.000000e+00 +; CHECK: ret float %t3 +} + +; once cause Crash/miscompilation +define float @fail1(float %f1, float %f2) { + %conv3 = fadd fast float %f1, -1.000000e+00 + %add = fadd fast float %conv3, %conv3 + %add2 = fadd fast float %add, %conv3 + ret float %add2 +; CHECK: @fail1 +; CHECK: ret +} + +define double @fail2(double %f1, double %f2) { + %t1 = fsub fast double %f1, %f2 + %t2 = fadd fast double %f1, %f2 + %t3 = fsub fast double %t1, %t2 + ret double %t3 +; CHECK: @fail2 +; CHECK: ret +} + +; c1 * x - x => (c1 - 1.0) * x +define float @fold13(float %x) { + %mul = fmul fast float %x, 7.000000e+00 + %sub = fsub fast float %mul, %x + ret float %sub +; CHECK: fold13 +; CHECK: fmul fast float %x, 6.000000e+00 +; CHECK: ret +} + +; ========================================================================= +; +; Testing-cases about fmul begin +; +; ========================================================================= + +; ((X*C1) + C2) * C3 => (X * (C1*C3)) + (C2*C3) (i.e. distribution) +define float @fmul_distribute1(float %f1) { + %t1 = fmul float %f1, 6.0e+3 + %t2 = fadd float %t1, 2.0e+3 + %t3 = fmul fast float %t2, 5.0e+3 + ret float %t3 +; CHECK: @fmul_distribute1 +; CHECK: %1 = fmul fast float %f1, 3.000000e+07 +; CHECK: %t3 = fadd fast float %1, 1.000000e+07 +} + +; (X/C1 + C2) * C3 => X/(C1/C3) + C2*C3 +define double @fmul_distribute2(double %f1, double %f2) { + %t1 = fdiv double %f1, 3.0e+0 + %t2 = fadd double %t1, 5.0e+1 + ; 0x10000000000000 = DBL_MIN + %t3 = fmul fast double %t2, 0x10000000000000 + ret double %t3 + +; CHECK: @fmul_distribute2 +; CHECK: %1 = fdiv fast double %f1, 0x7FE8000000000000 +; CHECK: fadd fast double %1, 0x69000000000000 +} + +; 5.0e-1 * DBL_MIN yields denormal, so "(f1*3.0 + 5.0e-1) * DBL_MIN" cannot +; be simplified into f1 * (3.0*DBL_MIN) + (5.0e-1*DBL_MIN) +define double @fmul_distribute3(double %f1) { + %t1 = fdiv double %f1, 3.0e+0 + %t2 = fadd double %t1, 5.0e-1 + %t3 = fmul fast double %t2, 0x10000000000000 + ret double %t3 + +; CHECK: @fmul_distribute3 +; CHECK: fmul fast double %t2, 0x10000000000000 +} + +; ((X*C1) + C2) * C3 => (X * (C1*C3)) + (C2*C3) (i.e. distribution) +define float @fmul_distribute4(float %f1) { + %t1 = fmul float %f1, 6.0e+3 + %t2 = fsub float 2.0e+3, %t1 + %t3 = fmul fast float %t2, 5.0e+3 + ret float %t3 +; CHECK: @fmul_distribute4 +; CHECK: %1 = fmul fast float %f1, 3.000000e+07 +; CHECK: %t3 = fsub fast float 1.000000e+07, %1 +} + +; C1/X * C2 => (C1*C2) / X +define float @fmul2(float %f1) { + %t1 = fdiv float 2.0e+3, %f1 + %t3 = fmul fast float %t1, 6.0e+3 + ret float %t3 +; CHECK: @fmul2 +; CHECK: fdiv fast float 1.200000e+07, %f1 +} + +; X/C1 * C2 => X * (C2/C1) (if C2/C1 is normal Fp) +define float @fmul3(float %f1, float %f2) { + %t1 = fdiv float %f1, 2.0e+3 + %t3 = fmul fast float %t1, 6.0e+3 + ret float %t3 +; CHECK: @fmul3 +; CHECK: fmul fast float %f1, 3.000000e+00 +} + +; Rule "X/C1 * C2 => X * (C2/C1) is not applicable if C2/C1 is either a special +; value of a denormal. The 0x3810000000000000 here take value FLT_MIN +; +define float @fmul4(float %f1, float %f2) { + %t1 = fdiv float %f1, 2.0e+3 + %t3 = fmul fast float %t1, 0x3810000000000000 + ret float %t3 +; CHECK: @fmul4 +; CHECK: fmul fast float %t1, 0x3810000000000000 +} + +; X / C1 * C2 => X / (C2/C1) if C1/C2 is either a special value of a denormal, +; and C2/C1 is a normal value. +; +define float @fmul5(float %f1, float %f2) { + %t1 = fdiv float %f1, 3.0e+0 + %t3 = fmul fast float %t1, 0x3810000000000000 + ret float %t3 +; CHECK: @fmul5 +; CHECK: fdiv fast float %f1, 0x47E8000000000000 +} + +; (X*Y) * X => (X*X) * Y +define float @fmul6(float %f1, float %f2) { + %mul = fmul float %f1, %f2 + %mul1 = fmul fast float %mul, %f1 + ret float %mul1 +; CHECK: @fmul6 +; CHECK: fmul fast float %f1, %f1 +} + +; "(X*Y) * X => (X*X) * Y" is disabled if "X*Y" has multiple uses +define float @fmul7(float %f1, float %f2) { + %mul = fmul float %f1, %f2 + %mul1 = fmul fast float %mul, %f1 + %add = fadd float %mul1, %mul + ret float %add +; CHECK: @fmul7 +; CHECK: fmul fast float %mul, %f1 +} + +; ========================================================================= +; +; Testing-cases about negation +; +; ========================================================================= +define float @fneg1(float %f1, float %f2) { + %sub = fsub float -0.000000e+00, %f1 + %sub1 = fsub nsz float 0.000000e+00, %f2 + %mul = fmul float %sub, %sub1 + ret float %mul +; CHECK: @fneg1 +; CHECK: fmul float %f1, %f2 +} + +; ========================================================================= +; +; Testing-cases about div +; +; ========================================================================= + +; X/C1 / C2 => X * (1/(C2*C1)) +define float @fdiv1(float %x) { + %div = fdiv float %x, 0x3FF3333340000000 + %div1 = fdiv fast float %div, 0x4002666660000000 + ret float %div1 +; 0x3FF3333340000000 = 1.2f +; 0x4002666660000000 = 2.3f +; 0x3FD7303B60000000 = 0.36231884057971014492 +; CHECK: @fdiv1 +; CHECK: fmul fast float %x, 0x3FD7303B60000000 +} + +; X*C1 / C2 => X * (C1/C2) +define float @fdiv2(float %x) { + %mul = fmul float %x, 0x3FF3333340000000 + %div1 = fdiv fast float %mul, 0x4002666660000000 + ret float %div1 + +; 0x3FF3333340000000 = 1.2f +; 0x4002666660000000 = 2.3f +; 0x3FE0B21660000000 = 0.52173918485641479492 +; CHECK: @fdiv2 +; CHECK: fmul fast float %x, 0x3FE0B21660000000 +} + +; "X/C1 / C2 => X * (1/(C2*C1))" is disabled (for now) is C2/C1 is a denormal +; +define float @fdiv3(float %x) { + %div = fdiv float %x, 0x47EFFFFFE0000000 + %div1 = fdiv fast float %div, 0x4002666660000000 + ret float %div1 +; CHECK: @fdiv3 +; CHECK: fdiv float %x, 0x47EFFFFFE0000000 +} + +; "X*C1 / C2 => X * (C1/C2)" is disabled if C1/C2 is a denormal +define float @fdiv4(float %x) { + %mul = fmul float %x, 0x47EFFFFFE0000000 + %div = fdiv float %mul, 0x3FC99999A0000000 + ret float %div +; CHECK: @fdiv4 +; CHECK: fmul float %x, 0x47EFFFFFE0000000 +} + +; (X/Y)/Z = > X/(Y*Z) +define float @fdiv5(float %f1, float %f2, float %f3) { + %t1 = fdiv float %f1, %f2 + %t2 = fdiv fast float %t1, %f3 + ret float %t2 +; CHECK: @fdiv5 +; CHECK: fmul float %f2, %f3 +} + +; Z/(X/Y) = > (Z*Y)/X +define float @fdiv6(float %f1, float %f2, float %f3) { + %t1 = fdiv float %f1, %f2 + %t2 = fdiv fast float %f3, %t1 + ret float %t2 +; CHECK: @fdiv6 +; CHECK: fmul float %f3, %f2 +} + +; C1/(X*C2) => (C1/C2) / X +define float @fdiv7(float %x) { + %t1 = fmul float %x, 3.0e0 + %t2 = fdiv fast float 15.0e0, %t1 + ret float %t2 +; CHECK: @fdiv7 +; CHECK: fdiv fast float 5.000000e+00, %x +} + +; C1/(X/C2) => (C1*C2) / X +define float @fdiv8(float %x) { + %t1 = fdiv float %x, 3.0e0 + %t2 = fdiv fast float 15.0e0, %t1 + ret float %t2 +; CHECK: @fdiv8 +; CHECK: fdiv fast float 4.500000e+01, %x +} + +; C1/(C2/X) => (C1/C2) * X +define float @fdiv9(float %x) { + %t1 = fdiv float 3.0e0, %x + %t2 = fdiv fast float 15.0e0, %t1 + ret float %t2 +; CHECK: @fdiv9 +; CHECK: fmul fast float %x, 5.000000e+00 +} + +; ========================================================================= +; +; Testing-cases about factorization +; +; ========================================================================= +; x*z + y*z => (x+y) * z +define float @fact_mul1(float %x, float %y, float %z) { + %t1 = fmul fast float %x, %z + %t2 = fmul fast float %y, %z + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: @fact_mul1 +; CHECK: fmul fast float %1, %z +} + +; z*x + y*z => (x+y) * z +define float @fact_mul2(float %x, float %y, float %z) { + %t1 = fmul fast float %z, %x + %t2 = fmul fast float %y, %z + %t3 = fsub fast float %t1, %t2 + ret float %t3 +; CHECK: @fact_mul2 +; CHECK: fmul fast float %1, %z +} + +; z*x - z*y => (x-y) * z +define float @fact_mul3(float %x, float %y, float %z) { + %t2 = fmul fast float %z, %y + %t1 = fmul fast float %z, %x + %t3 = fsub fast float %t1, %t2 + ret float %t3 +; CHECK: @fact_mul3 +; CHECK: fmul fast float %1, %z +} + +; x*z - z*y => (x-y) * z +define float @fact_mul4(float %x, float %y, float %z) { + %t1 = fmul fast float %x, %z + %t2 = fmul fast float %z, %y + %t3 = fsub fast float %t1, %t2 + ret float %t3 +; CHECK: @fact_mul4 +; CHECK: fmul fast float %1, %z +} + +; x/y + x/z, no xform +define float @fact_div1(float %x, float %y, float %z) { + %t1 = fdiv fast float %x, %y + %t2 = fdiv fast float %x, %z + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: fact_div1 +; CHECK: fadd fast float %t1, %t2 +} + +; x/y + z/x; no xform +define float @fact_div2(float %x, float %y, float %z) { + %t1 = fdiv fast float %x, %y + %t2 = fdiv fast float %z, %x + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: fact_div2 +; CHECK: fadd fast float %t1, %t2 +} + +; y/x + z/x => (y+z)/x +define float @fact_div3(float %x, float %y, float %z) { + %t1 = fdiv fast float %y, %x + %t2 = fdiv fast float %z, %x + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: fact_div3 +; CHECK: fdiv fast float %1, %x +} + +; y/x - z/x => (y-z)/x +define float @fact_div4(float %x, float %y, float %z) { + %t1 = fdiv fast float %y, %x + %t2 = fdiv fast float %z, %x + %t3 = fsub fast float %t1, %t2 + ret float %t3 +; CHECK: fact_div4 +; CHECK: fdiv fast float %1, %x +} + +; y/x - z/x => (y-z)/x is disabled if y-z is denormal. +define float @fact_div5(float %x) { + %t1 = fdiv fast float 0x3810000000000000, %x + %t2 = fdiv fast float 0x3800000000000000, %x + %t3 = fadd fast float %t1, %t2 + ret float %t3 +; CHECK: fact_div5 +; CHECK: fdiv fast float 0x3818000000000000, %x +} + +; y/x - z/x => (y-z)/x is disabled if y-z is denormal. +define float @fact_div6(float %x) { + %t1 = fdiv fast float 0x3810000000000000, %x + %t2 = fdiv fast float 0x3800000000000000, %x + %t3 = fsub fast float %t1, %t2 + ret float %t3 +; CHECK: fact_div6 +; CHECK: %t3 = fsub fast float %t1, %t2 +} diff --git a/test/Transforms/InstCombine/ffs-1.ll b/test/Transforms/InstCombine/ffs-1.ll new file mode 100644 index 0000000000000..0510df3d24b9a --- /dev/null +++ b/test/Transforms/InstCombine/ffs-1.ll @@ -0,0 +1,134 @@ +; Test that the ffs* library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s +; RUN: opt < %s -mtriple i386-pc-linux -instcombine -S | FileCheck %s -check-prefix=LINUX + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare i32 @ffs(i32) +declare i32 @ffsl(i32) +declare i32 @ffsll(i64) + +; Check ffs(0) -> 0. + +define i32 @test_simplify1() { +; CHECK: @test_simplify1 + %ret = call i32 @ffs(i32 0) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify2() { +; CHECK-LINUX: @test_simplify2 + %ret = call i32 @ffsl(i32 0) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 0 +} + +define i32 @test_simplify3() { +; CHECK-LINUX: @test_simplify3 + %ret = call i32 @ffsll(i64 0) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 0 +} + +; Check ffs(c) -> cttz(c) + 1, where 'c' is a constant. + +define i32 @test_simplify4() { +; CHECK: @test_simplify4 + %ret = call i32 @ffs(i32 1) + ret i32 %ret +; CHECK-NEXT: ret i32 1 +} + +define i32 @test_simplify5() { +; CHECK: @test_simplify5 + %ret = call i32 @ffs(i32 2048) + ret i32 %ret +; CHECK-NEXT: ret i32 12 +} + +define i32 @test_simplify6() { +; CHECK: @test_simplify6 + %ret = call i32 @ffs(i32 65536) + ret i32 %ret +; CHECK-NEXT: ret i32 17 +} + +define i32 @test_simplify7() { +; CHECK-LINUX: @test_simplify7 + %ret = call i32 @ffsl(i32 65536) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 17 +} + +define i32 @test_simplify8() { +; CHECK-LINUX: @test_simplify8 + %ret = call i32 @ffsll(i64 1024) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 11 +} + +define i32 @test_simplify9() { +; CHECK-LINUX: @test_simplify9 + %ret = call i32 @ffsll(i64 65536) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 17 +} + +define i32 @test_simplify10() { +; CHECK-LINUX: @test_simplify10 + %ret = call i32 @ffsll(i64 17179869184) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 35 +} + +define i32 @test_simplify11() { +; CHECK-LINUX: @test_simplify11 + %ret = call i32 @ffsll(i64 281474976710656) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 49 +} + +define i32 @test_simplify12() { +; CHECK-LINUX: @test_simplify12 + %ret = call i32 @ffsll(i64 1152921504606846976) + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 61 +} + +; Check ffs(x) -> x != 0 ? (i32)llvm.cttz(x) + 1 : 0. + +define i32 @test_simplify13(i32 %x) { +; CHECK: @test_simplify13 + %ret = call i32 @ffs(i32 %x) +; CHECK-NEXT: [[CTTZ:%[a-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %x, i1 false) +; CHECK-NEXT: [[INC:%[a-z0-9]+]] = add i32 [[CTTZ]], 1 +; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %x, 0 +; CHECK-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[INC]], i32 0 + ret i32 %ret +; CHECK-NEXT: ret i32 [[RET]] +} + +define i32 @test_simplify14(i32 %x) { +; CHECK-LINUX: @test_simplify14 + %ret = call i32 @ffsl(i32 %x) +; CHECK-LINUX-NEXT: [[CTTZ:%[a-z0-9]+]] = call i32 @llvm.cttz.i32(i32 %x, i1 false) +; CHECK-LINUX-NEXT: [[INC:%[a-z0-9]+]] = add i32 [[CTTZ]], 1 +; CHECK-LINUX-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %x, 0 +; CHECK-LINUX-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[INC]], i32 0 + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 [[RET]] +} + +define i32 @test_simplify15(i64 %x) { +; CHECK-LINUX: @test_simplify15 + %ret = call i32 @ffsll(i64 %x) +; CHECK-LINUX-NEXT: [[CTTZ:%[a-z0-9]+]] = call i64 @llvm.cttz.i64(i64 %x, i1 false) +; CHECK-LINUX-NEXT: [[INC:%[a-z0-9]+]] = add i64 [[CTTZ]], 1 +; CHECK-LINUX-NEXT: [[TRUNC:%[a-z0-9]+]] = trunc i64 [[INC]] to i32 +; CHECK-LINUX-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i64 %x, 0 +; CHECK-LINUX-NEXT: [[RET:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[TRUNC]], i32 0 + ret i32 %ret +; CHECK-LINUX-NEXT: ret i32 [[RET]] +} diff --git a/test/Transforms/InstCombine/fmul.ll b/test/Transforms/InstCombine/fmul.ll new file mode 100644 index 0000000000000..3671b4c6991cb --- /dev/null +++ b/test/Transforms/InstCombine/fmul.ll @@ -0,0 +1,72 @@ +; RUN: opt -S -instcombine < %s | FileCheck %s + +; (-0.0 - X) * C => X * -C +define float @test1(float %x) { + %sub = fsub float -0.000000e+00, %x + %mul = fmul float %sub, 2.0e+1 + ret float %mul + +; CHECK: @test1 +; CHECK: fmul float %x, -2.000000e+01 +} + +; (0.0 - X) * C => X * -C +define float @test2(float %x) { + %sub = fsub nsz float 0.000000e+00, %x + %mul = fmul float %sub, 2.0e+1 + ret float %mul + +; CHECK: @test2 +; CHECK: fmul float %x, -2.000000e+01 +} + +; (-0.0 - X) * (-0.0 - Y) => X * Y +define float @test3(float %x, float %y) { + %sub1 = fsub float -0.000000e+00, %x + %sub2 = fsub float -0.000000e+00, %y + %mul = fmul float %sub1, %sub2 + ret float %mul +; CHECK: @test3 +; CHECK: fmul float %x, %y +} + +; (0.0 - X) * (0.0 - Y) => X * Y +define float @test4(float %x, float %y) { + %sub1 = fsub nsz float 0.000000e+00, %x + %sub2 = fsub nsz float 0.000000e+00, %y + %mul = fmul float %sub1, %sub2 + ret float %mul +; CHECK: @test4 +; CHECK: fmul float %x, %y +} + +; (-0.0 - X) * Y => -0.0 - (X * Y) +define float @test5(float %x, float %y) { + %sub1 = fsub float -0.000000e+00, %x + %mul = fmul float %sub1, %y + ret float %mul +; CHECK: @test5 +; CHECK: %1 = fmul float %x, %y +; CHECK: %mul = fsub float -0.000000e+00, %1 +} + +; (0.0 - X) * Y => 0.0 - (X * Y) +define float @test6(float %x, float %y) { + %sub1 = fsub nsz float 0.000000e+00, %x + %mul = fmul float %sub1, %y + ret float %mul +; CHECK: @test6 +; CHECK: %1 = fmul float %x, %y +; CHECK: %mul = fsub float -0.000000e+00, %1 +} + +; "(-0.0 - X) * Y => -0.0 - (X * Y)" is disabled if expression "-0.0 - X" +; has multiple uses. +define float @test7(float %x, float %y) { + %sub1 = fsub float -0.000000e+00, %x + %mul = fmul float %sub1, %y + %mul2 = fmul float %mul, %sub1 + ret float %mul2 +; CHECK: @test7 +; CHECK: fsub float -0.000000e+00, %x +} diff --git a/test/Transforms/InstCombine/fold-phi.ll b/test/Transforms/InstCombine/fold-phi.ll new file mode 100644 index 0000000000000..bd01d58aa5860 --- /dev/null +++ b/test/Transforms/InstCombine/fold-phi.ll @@ -0,0 +1,39 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +; CHECK: no_crash +define float @no_crash(float %a) nounwind { +entry: + br label %for.body + +for.body: + %sum.057 = phi float [ 0.000000e+00, %entry ], [ %add5, %bb0 ] + %add5 = fadd float %sum.057, %a ; PR14592 + br i1 undef, label %bb0, label %end + +bb0: + br label %for.body + +end: + ret float %add5 +} + +; CHECK: fold_phi +define float @fold_phi(float %a) nounwind { +entry: + br label %for.body + +for.body: +; CHECK: phi float +; CHECK-NEXT: br i1 undef + %sum.057 = phi float [ 0.000000e+00, %entry ], [ %add5, %bb0 ] + %add5 = fadd float %sum.057, 1.0 ;; Should be moved to the latch! + br i1 undef, label %bb0, label %end + +; CHECK: bb0: +bb0: +; CHECK: fadd float + br label %for.body + +end: + ret float %add5 +} diff --git a/test/Transforms/InstCombine/fpcast.ll b/test/Transforms/InstCombine/fpcast.ll index bc6aa0a6891f6..09f053289dc17 100644 --- a/test/Transforms/InstCombine/fpcast.ll +++ b/test/Transforms/InstCombine/fpcast.ll @@ -13,3 +13,22 @@ define i8 @test2() { ; CHECK: ret i8 -1 } +; CHECK: test3 +define half @test3(float %a) { +; CHECK: fptrunc +; CHECK: llvm.fabs.f16 + %b = call float @llvm.fabs.f32(float %a) + %c = fptrunc float %b to half + ret half %c +} + +; CHECK: test4 +define half @test4(float %a) { +; CHECK: fptrunc +; CHECK: fsub + %b = fsub float -0.0, %a + %c = fptrunc float %b to half + ret half %c +} + +declare float @llvm.fabs.f32(float) nounwind readonly diff --git a/test/Transforms/InstCombine/fprintf-1.ll b/test/Transforms/InstCombine/fprintf-1.ll new file mode 100644 index 0000000000000..39d86b4588cc8 --- /dev/null +++ b/test/Transforms/InstCombine/fprintf-1.ll @@ -0,0 +1,80 @@ +; Test that the fprintf library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s +; RUN: opt < %s -mtriple xcore-xmos-elf -instcombine -S | FileCheck %s -check-prefix=IPRINTF + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +%FILE = type { } + +@hello_world = constant [13 x i8] c"hello world\0A\00" +@percent_c = constant [3 x i8] c"%c\00" +@percent_d = constant [3 x i8] c"%d\00" +@percent_f = constant [3 x i8] c"%f\00" +@percent_s = constant [3 x i8] c"%s\00" + +declare i32 @fprintf(%FILE*, i8*, ...) + +; Check fprintf(fp, "foo") -> fwrite("foo", 3, 1, fp). + +define void @test_simplify1(%FILE* %fp) { +; CHECK: @test_simplify1 + %fmt = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt) +; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([13 x i8]* @hello_world, i32 0, i32 0), i32 12, i32 1, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +; Check fprintf(fp, "%c", chr) -> fputc(chr, fp). + +define void @test_simplify2(%FILE* %fp) { +; CHECK: @test_simplify2 + %fmt = getelementptr [3 x i8]* @percent_c, i32 0, i32 0 + call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt, i8 104) +; CHECK-NEXT: call i32 @fputc(i32 104, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +; Check fprintf(fp, "%s", str) -> fputs(str, fp). +; NOTE: The fputs simplifier simplifies this further to fwrite. + +define void @test_simplify3(%FILE* %fp) { +; CHECK: @test_simplify3 + %fmt = getelementptr [3 x i8]* @percent_s, i32 0, i32 0 + %str = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt, i8* %str) +; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([13 x i8]* @hello_world, i32 0, i32 0), i32 12, i32 1, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +; Check fprintf(fp, fmt, ...) -> fiprintf(fp, fmt, ...) if no floating point. + +define void @test_simplify4(%FILE* %fp) { +; CHECK-IPRINTF: @test_simplify4 + %fmt = getelementptr [3 x i8]* @percent_d, i32 0, i32 0 + call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt, i32 187) +; CHECK-NEXT-IPRINTF: call i32 (%FILE*, i8*, ...)* @fiprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8]* @percent_d, i32 0, i32 0), i32 187) + ret void +; CHECK-NEXT-IPRINTF: ret void +} + +define void @test_no_simplify1(%FILE* %fp) { +; CHECK-IPRINTF: @test_no_simplify1 + %fmt = getelementptr [3 x i8]* @percent_f, i32 0, i32 0 + call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt, double 1.87) +; CHECK-NEXT-IPRINTF: call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) + ret void +; CHECK-NEXT-IPRINTF: ret void +} + +define void @test_no_simplify2(%FILE* %fp, double %d) { +; CHECK: @test_no_simplify2 + %fmt = getelementptr [3 x i8]* @percent_f, i32 0, i32 0 + call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* %fmt, double %d) +; CHECK-NEXT: call i32 (%FILE*, i8*, ...)* @fprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8]* @percent_f, i32 0, i32 0), double %d) + ret void +; CHECK-NEXT: ret void +} diff --git a/test/Transforms/InstCombine/fputs-1.ll b/test/Transforms/InstCombine/fputs-1.ll new file mode 100644 index 0000000000000..c7c5becfd038c --- /dev/null +++ b/test/Transforms/InstCombine/fputs-1.ll @@ -0,0 +1,43 @@ +; Test that the fputs library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +%FILE = type { } + +@empty = constant [1 x i8] zeroinitializer +@A = constant [2 x i8] c"A\00" +@hello = constant [7 x i8] c"hello\0A\00" + +declare i32 @fputs(i8*, %FILE*) + +; Check fputs(str, fp) --> fwrite(str, 1, strlen(s), fp). + +define void @test_simplify1(%FILE* %fp) { +; CHECK: @test_simplify1 + %str = getelementptr [1 x i8]* @empty, i32 0, i32 0 + call i32 @fputs(i8* %str, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +; NOTE: The fwrite simplifier simplifies this further to fputc. + +define void @test_simplify2(%FILE* %fp) { +; CHECK: @test_simplify2 + %str = getelementptr [2 x i8]* @A, i32 0, i32 0 + call i32 @fputs(i8* %str, %FILE* %fp) +; CHECK-NEXT: call i32 @fputc(i32 65, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify3(%FILE* %fp) { +; CHECK: @test_simplify3 + %str = getelementptr [7 x i8]* @hello, i32 0, i32 0 + call i32 @fputs(i8* %str, %FILE* %fp) +; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([7 x i8]* @hello, i32 0, i32 0), i32 6, i32 1, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} diff --git a/test/Transforms/InstCombine/fwrite-1.ll b/test/Transforms/InstCombine/fwrite-1.ll new file mode 100644 index 0000000000000..528cdec217f7e --- /dev/null +++ b/test/Transforms/InstCombine/fwrite-1.ll @@ -0,0 +1,57 @@ +; Test that the fwrite library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +%FILE = type { } + +@str = constant [1 x i8] zeroinitializer +@empty = constant [0 x i8] zeroinitializer + +declare i64 @fwrite(i8*, i64, i64, %FILE *) + +; Check fwrite(S, 1, 1, fp) -> fputc(S[0], fp). + +define void @test_simplify1(%FILE* %fp) { +; CHECK: @test_simplify1 + %str = getelementptr inbounds [1 x i8]* @str, i64 0, i64 0 + call i64 @fwrite(i8* %str, i64 1, i64 1, %FILE* %fp) +; CHECK-NEXT: call i32 @fputc(i32 0, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify2(%FILE* %fp) { +; CHECK: @test_simplify2 + %str = getelementptr inbounds [0 x i8]* @empty, i64 0, i64 0 + call i64 @fwrite(i8* %str, i64 1, i64 0, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify3(%FILE* %fp) { +; CHECK: @test_simplify3 + %str = getelementptr inbounds [0 x i8]* @empty, i64 0, i64 0 + call i64 @fwrite(i8* %str, i64 0, i64 1, %FILE* %fp) + ret void +; CHECK-NEXT: ret void +} + +define i64 @test_no_simplify1(%FILE* %fp) { +; CHECK: @test_no_simplify1 + %str = getelementptr inbounds [1 x i8]* @str, i64 0, i64 0 + %ret = call i64 @fwrite(i8* %str, i64 1, i64 1, %FILE* %fp) +; CHECK-NEXT: call i64 @fwrite + ret i64 %ret +; CHECK-NEXT: ret i64 %ret +} + +define void @test_no_simplify2(%FILE* %fp, i64 %size) { +; CHECK: @test_no_simplify2 + %str = getelementptr inbounds [1 x i8]* @str, i64 0, i64 0 + call i64 @fwrite(i8* %str, i64 %size, i64 1, %FILE* %fp) +; CHECK-NEXT: call i64 @fwrite + ret void +; CHECK-NEXT: ret void +} diff --git a/test/Transforms/InstCombine/getelementptr.ll b/test/Transforms/InstCombine/getelementptr.ll index 1c120ecbe9eb7..bb07736ef8037 100644 --- a/test/Transforms/InstCombine/getelementptr.ll +++ b/test/Transforms/InstCombine/getelementptr.ll @@ -424,7 +424,7 @@ define i32 @test35() nounwind { i8* getelementptr (%t1* bitcast (%t0* @s to %t1*), i32 0, i32 1, i32 0)) nounwind ret i32 0 ; CHECK: @test35 -; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* getelementptr inbounds (%t0* @s, i64 0, i32 1, i64 0)) nounwind +; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* getelementptr inbounds (%t0* @s, i64 0, i32 1, i64 0)) [[NUW:#[0-9]+]] } ; Instcombine should constant-fold the GEP so that indices that have @@ -492,3 +492,21 @@ define void @three_gep_f(%three_gep_t2* %x) { declare void @three_gep_g(i32*) declare void @three_gep_h(%three_gep_t2*) + +%struct.ham = type { i32, %struct.zot*, %struct.zot*, %struct.zot* } +%struct.zot = type { i64, i8 } + +define void @test39(%struct.ham* %arg, i8 %arg1) nounwind { + %tmp = getelementptr inbounds %struct.ham* %arg, i64 0, i32 2 + %tmp2 = load %struct.zot** %tmp, align 8 + %tmp3 = bitcast %struct.zot* %tmp2 to i8* + %tmp4 = getelementptr inbounds i8* %tmp3, i64 -8 + store i8 %arg1, i8* %tmp4, align 8 + ret void + +; CHECK: @test39 +; CHECK: getelementptr inbounds %struct.ham* %arg, i64 0, i32 2 +; CHECK: getelementptr inbounds i8* %tmp3, i64 -8 +} + +; CHECK: attributes [[NUW]] = { nounwind } diff --git a/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index 8e064a4f2fc94..446c0e01dcaa5 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/test/Transforms/InstCombine/icmp.ll @@ -677,3 +677,212 @@ define i1 @test66(i64 %A, i64 %B) { ; CHECK-NEXT: ret i1 true ret i1 %cmp } + +; CHECK: @test67 +; CHECK: %and = and i32 %x, 96 +; CHECK: %cmp = icmp ne i32 %and, 0 +define i1 @test67(i32 %x) nounwind uwtable { + %and = and i32 %x, 127 + %cmp = icmp sgt i32 %and, 31 + ret i1 %cmp +} + +; CHECK: @test68 +; CHECK: %cmp = icmp ugt i32 %and, 30 +define i1 @test68(i32 %x) nounwind uwtable { + %and = and i32 %x, 127 + %cmp = icmp sgt i32 %and, 30 + ret i1 %cmp +} + +; PR14708 +; CHECK: @test69 +; CHECK: %1 = and i32 %c, -33 +; CHECK: %2 = icmp eq i32 %1, 65 +; CHECK: ret i1 %2 +define i1 @test69(i32 %c) nounwind uwtable { + %1 = icmp eq i32 %c, 97 + %2 = icmp eq i32 %c, 65 + %3 = or i1 %1, %2 + ret i1 %3 +} + +; CHECK: @icmp_sext16trunc +; CHECK-NEXT: %1 = trunc i32 %x to i16 +; CHECK-NEXT: %cmp = icmp slt i16 %1, 36 +define i1 @icmp_sext16trunc(i32 %x) { + %trunc = trunc i32 %x to i16 + %sext = sext i16 %trunc to i32 + %cmp = icmp slt i32 %sext, 36 + ret i1 %cmp +} + +; CHECK: @icmp_sext8trunc +; CHECK-NEXT: %1 = trunc i32 %x to i8 +; CHECK-NEXT: %cmp = icmp slt i8 %1, 36 +define i1 @icmp_sext8trunc(i32 %x) { + %trunc = trunc i32 %x to i8 + %sext = sext i8 %trunc to i32 + %cmp = icmp slt i32 %sext, 36 + ret i1 %cmp +} + +; CHECK: @icmp_shl16 +; CHECK-NEXT: %1 = trunc i32 %x to i16 +; CHECK-NEXT: %cmp = icmp slt i16 %1, 36 +define i1 @icmp_shl16(i32 %x) { + %shl = shl i32 %x, 16 + %cmp = icmp slt i32 %shl, 2359296 + ret i1 %cmp +} + +; CHECK: @icmp_shl24 +; CHECK-NEXT: %1 = trunc i32 %x to i8 +; CHECK-NEXT: %cmp = icmp slt i8 %1, 36 +define i1 @icmp_shl24(i32 %x) { + %shl = shl i32 %x, 24 + %cmp = icmp slt i32 %shl, 603979776 + ret i1 %cmp +} + +; If the (shl x, C) preserved the sign and this is a sign test, +; compare the LHS operand instead +; CHECK: @icmp_shl_nsw_sgt +; CHECK-NEXT: icmp sgt i32 %x, 0 +define i1 @icmp_shl_nsw_sgt(i32 %x) { + %shl = shl nsw i32 %x, 21 + %cmp = icmp sgt i32 %shl, 0 + ret i1 %cmp +} + +; CHECK: @icmp_shl_nsw_sge0 +; CHECK-NEXT: icmp sgt i32 %x, -1 +define i1 @icmp_shl_nsw_sge0(i32 %x) { + %shl = shl nsw i32 %x, 21 + %cmp = icmp sge i32 %shl, 0 + ret i1 %cmp +} + +; CHECK: @icmp_shl_nsw_sge1 +; CHECK-NEXT: icmp sgt i32 %x, 0 +define i1 @icmp_shl_nsw_sge1(i32 %x) { + %shl = shl nsw i32 %x, 21 + %cmp = icmp sge i32 %shl, 1 + ret i1 %cmp +} + +; Checks for icmp (eq|ne) (shl x, C), 0 +; CHECK: @icmp_shl_nsw_eq +; CHECK-NEXT: icmp eq i32 %x, 0 +define i1 @icmp_shl_nsw_eq(i32 %x) { + %mul = shl nsw i32 %x, 5 + %cmp = icmp eq i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_shl_eq +; CHECK-NOT: icmp eq i32 %mul, 0 +define i1 @icmp_shl_eq(i32 %x) { + %mul = shl i32 %x, 5 + %cmp = icmp eq i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_shl_nsw_ne +; CHECK-NEXT: icmp ne i32 %x, 0 +define i1 @icmp_shl_nsw_ne(i32 %x) { + %mul = shl nsw i32 %x, 7 + %cmp = icmp ne i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_shl_ne +; CHECK-NOT: icmp ne i32 %x, 0 +define i1 @icmp_shl_ne(i32 %x) { + %mul = shl i32 %x, 7 + %cmp = icmp ne i32 %mul, 0 + ret i1 %cmp +} + +; If the (mul x, C) preserved the sign and this is sign test, +; compare the LHS operand instead +; CHECK: @icmp_mul_nsw +; CHECK-NEXT: icmp sgt i32 %x, 0 +define i1 @icmp_mul_nsw(i32 %x) { + %mul = mul nsw i32 %x, 12 + %cmp = icmp sgt i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_mul_nsw1 +; CHECK-NEXT: icmp slt i32 %x, 0 +define i1 @icmp_mul_nsw1(i32 %x) { + %mul = mul nsw i32 %x, 12 + %cmp = icmp sle i32 %mul, -1 + ret i1 %cmp +} + +; CHECK: @icmp_mul_nsw_neg +; CHECK-NEXT: icmp slt i32 %x, 1 +define i1 @icmp_mul_nsw_neg(i32 %x) { + %mul = mul nsw i32 %x, -12 + %cmp = icmp sge i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_mul_nsw_neg1 +; CHECK-NEXT: icmp slt i32 %x, 0 +define i1 @icmp_mul_nsw_neg1(i32 %x) { + %mul = mul nsw i32 %x, -12 + %cmp = icmp sge i32 %mul, 1 + ret i1 %cmp +} + +; CHECK: @icmp_mul_nsw_0 +; CHECK-NOT: icmp sgt i32 %x, 0 +define i1 @icmp_mul_nsw_0(i32 %x) { + %mul = mul nsw i32 %x, 0 + %cmp = icmp sgt i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_mul +; CHECK-NEXT: %mul = mul i32 %x, -12 +define i1 @icmp_mul(i32 %x) { + %mul = mul i32 %x, -12 + %cmp = icmp sge i32 %mul, 0 + ret i1 %cmp +} + +; Checks for icmp (eq|ne) (mul x, C), 0 +; CHECK: @icmp_mul_neq0 +; CHECK-NEXT: icmp ne i32 %x, 0 +define i1 @icmp_mul_neq0(i32 %x) { + %mul = mul nsw i32 %x, -12 + %cmp = icmp ne i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_mul_eq0 +; CHECK-NEXT: icmp eq i32 %x, 0 +define i1 @icmp_mul_eq0(i32 %x) { + %mul = mul nsw i32 %x, 12 + %cmp = icmp eq i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_mul0_eq0 +; CHECK-NEXT: ret i1 true +define i1 @icmp_mul0_eq0(i32 %x) { + %mul = mul i32 %x, 0 + %cmp = icmp eq i32 %mul, 0 + ret i1 %cmp +} + +; CHECK: @icmp_mul0_ne0 +; CHECK-NEXT: ret i1 false +define i1 @icmp_mul0_ne0(i32 %x) { + %mul = mul i32 %x, 0 + %cmp = icmp ne i32 %mul, 0 + ret i1 %cmp +} diff --git a/test/Transforms/InstCombine/idioms.ll b/test/Transforms/InstCombine/idioms.ll index 6b3567fc6e8d6..1a211668c3bf5 100644 --- a/test/Transforms/InstCombine/idioms.ll +++ b/test/Transforms/InstCombine/idioms.ll @@ -1,4 +1,4 @@ -; RUN: opt -instcombine %s -S | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s ; Check that code corresponding to the following C function is ; simplified into a single ASR operation: diff --git a/test/Transforms/InstCombine/intrinsics.ll b/test/Transforms/InstCombine/intrinsics.ll index 382e6b38574d0..f334b3b1e9353 100644 --- a/test/Transforms/InstCombine/intrinsics.ll +++ b/test/Transforms/InstCombine/intrinsics.ll @@ -1,4 +1,4 @@ -; RUN: opt %s -instcombine -S | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s %overflow.result = type {i8, i1} @@ -220,3 +220,39 @@ define i32 @cttz_simplify1b(i32 %x) nounwind readnone ssp { ; CHECK: @cttz_simplify1b ; CHECK-NEXT: ret i32 0 } + +define i32 @ctlz_undef(i32 %Value) nounwind { + %ctlz = call i32 @llvm.ctlz.i32(i32 0, i1 true) + ret i32 %ctlz + +; CHECK: @ctlz_undef +; CHECK-NEXT: ret i32 undef +} + +define i32 @cttz_undef(i32 %Value) nounwind { + %cttz = call i32 @llvm.cttz.i32(i32 0, i1 true) + ret i32 %cttz + +; CHECK: @cttz_undef +; CHECK-NEXT: ret i32 undef +} + +define i32 @ctlz_select(i32 %Value) nounwind { + %tobool = icmp ne i32 %Value, 0 + %ctlz = call i32 @llvm.ctlz.i32(i32 %Value, i1 true) + %s = select i1 %tobool, i32 %ctlz, i32 32 + ret i32 %s + +; CHECK: @ctlz_select +; CHECK: select i1 %tobool, i32 %ctlz, i32 32 +} + +define i32 @cttz_select(i32 %Value) nounwind { + %tobool = icmp ne i32 %Value, 0 + %cttz = call i32 @llvm.cttz.i32(i32 %Value, i1 true) + %s = select i1 %tobool, i32 %cttz, i32 32 + ret i32 %s + +; CHECK: @cttz_select +; CHECK: select i1 %tobool, i32 %cttz, i32 32 +} diff --git a/test/Transforms/InstCombine/isascii-1.ll b/test/Transforms/InstCombine/isascii-1.ll new file mode 100644 index 0000000000000..2a413d89b4923 --- /dev/null +++ b/test/Transforms/InstCombine/isascii-1.ll @@ -0,0 +1,32 @@ +; Test that the isascii library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare i32 @isascii(i32) + +; Check isascii(c) -> c <u 128. + +define i32 @test_simplify1() { +; CHECK: @test_simplify1 + %ret = call i32 @isascii(i32 127) + ret i32 %ret +; CHECK-NEXT: ret i32 1 +} + +define i32 @test_simplify2() { +; CHECK: @test_simplify2 + %ret = call i32 @isascii(i32 128) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify3(i32 %x) { +; CHECK: @test_simplify3 + %ret = call i32 @isascii(i32 %x) +; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %x, 128 +; CHECK-NEXT: [[ZEXT:%[a-z0-9]+]] = zext i1 [[CMP]] to i32 + ret i32 %ret +; CHECK-NEXT: ret i32 [[ZEXT]] +} diff --git a/test/Transforms/InstCombine/isdigit-1.ll b/test/Transforms/InstCombine/isdigit-1.ll new file mode 100644 index 0000000000000..f291296c88266 --- /dev/null +++ b/test/Transforms/InstCombine/isdigit-1.ll @@ -0,0 +1,48 @@ +; Test that the isdigit library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare i32 @isdigit(i32) + +; Check isdigit(c) -> (c - '0') <u 10; + +define i32 @test_simplify1() { +; CHECK: @test_simplify1 + %ret = call i32 @isdigit(i32 47) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify2() { +; CHECK: @test_simplify2 + %ret = call i32 @isdigit(i32 48) + ret i32 %ret +; CHECK-NEXT: ret i32 1 +} + +define i32 @test_simplify3() { +; CHECK: @test_simplify3 + %ret = call i32 @isdigit(i32 57) + ret i32 %ret +; CHECK-NEXT: ret i32 1 +} + +define i32 @test_simplify4() { +; CHECK: @test_simplify4 + %ret = call i32 @isdigit(i32 58) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify5(i32 %x) { +; CHECK: @test_simplify5 + + %ret = call i32 @isdigit(i32 %x) +; CHECK-NEXT: [[ADD:%[a-z0-9]+]] = add i32 %x, -48 +; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 [[ADD]], 10 +; CHECK-NEXT: [[ZEXT:%[a-z0-9]+]] = zext i1 [[CMP]] to i32 + ret i32 %ret +; CHECK-NEXT: ret i32 [[ZEXT]] +} diff --git a/test/Transforms/InstCombine/load-cmp.ll b/test/Transforms/InstCombine/load-cmp.ll index 5cafb7787e36a..d88188e4109cd 100644 --- a/test/Transforms/InstCombine/load-cmp.ll +++ b/test/Transforms/InstCombine/load-cmp.ll @@ -47,6 +47,18 @@ define i1 @test4(i32 %X) { ; CHECK-NEXT: ret i1 %R } +define i1 @test4_i16(i16 %X) { + %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i16 %X + %Q = load i16* %P + %R = icmp sle i16 %Q, 73 + ret i1 %R +; CHECK: @test4_i16 +; CHECK-NEXT: lshr i16 933, %X +; CHECK-NEXT: and i16 {{.*}}, 1 +; CHECK-NEXT: %R = icmp ne i16 {{.*}}, 0 +; CHECK-NEXT: ret i1 %R +} + define i1 @test5(i32 %X) { %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X %Q = load i16* %P diff --git a/test/Transforms/InstCombine/load3.ll b/test/Transforms/InstCombine/load3.ll index 35398e17db8cc..db74426783c1f 100644 --- a/test/Transforms/InstCombine/load3.ll +++ b/test/Transforms/InstCombine/load3.ll @@ -1,6 +1,6 @@ ; RUN: opt < %s -instcombine -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" -target triple = "x86_64-apple-darwin10.0.0" +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128" +target triple = "i386-apple-macosx10.0.0" ; Instcombine should be able to do trivial CSE of loads. @@ -24,4 +24,23 @@ define float @test2() { ; CHECK: @test2 ; CHECK: ret float 0x3806965600000000 -}
\ No newline at end of file +} + +@rslts32 = global [36 x i32] zeroinitializer, align 4 + +@expect32 = internal constant [36 x i32][ i32 1, i32 2, i32 0, i32 100, i32 3, +i32 4, i32 0, i32 -7, i32 4, i32 4, i32 8, i32 8, i32 1, i32 3, i32 8, i32 3, +i32 4, i32 -2, i32 2, i32 8, i32 83, i32 77, i32 8, i32 17, i32 77, i32 88, i32 +22, i32 33, i32 44, i32 88, i32 77, i32 4, i32 4, i32 7, i32 -7, i32 -8] , +align 4 + +; PR14986 +define void @test3() nounwind { +; This is a weird way of computing zero. + %l = load i32* getelementptr ([36 x i32]* @expect32, i32 29826161, i32 28), align 4 + store i32 %l, i32* getelementptr ([36 x i32]* @rslts32, i32 29826161, i32 28), align 4 + ret void + +; CHECK: @test3 +; CHECK: store i32 1, i32* getelementptr inbounds ([36 x i32]* @rslts32, i32 0, i32 0) +} diff --git a/test/Transforms/InstCombine/logical-select.ll b/test/Transforms/InstCombine/logical-select.ll index bb59817a4f698..f8c06768453da 100644 --- a/test/Transforms/InstCombine/logical-select.ll +++ b/test/Transforms/InstCombine/logical-select.ll @@ -10,8 +10,8 @@ define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { %j = or i32 %g, %i ret i32 %j ; CHECK: %e = icmp slt i32 %a, %b -; CHECK: %j = select i1 %e, i32 %c, i32 %d -; CHECK: ret i32 %j +; CHECK-NEXT: [[result:%.*]] = select i1 %e, i32 %c, i32 %d +; CHECK-NEXT: ret i32 [[result]] } define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { %e = icmp slt i32 %a, %b @@ -22,8 +22,8 @@ define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { %j = or i32 %i, %g ret i32 %j ; CHECK: %e = icmp slt i32 %a, %b -; CHECK: %j = select i1 %e, i32 %c, i32 %d -; CHECK: ret i32 %j +; CHECK-NEXT: [[result:%.*]] = select i1 %e, i32 %c, i32 %d +; CHECK-NEXT: ret i32 [[result]] } define i32 @goo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { @@ -36,8 +36,8 @@ entry: %3 = or i32 %1, %2 ret i32 %3 ; CHECK: %0 = icmp slt i32 %a, %b -; CHECK: %1 = select i1 %0, i32 %c, i32 %d -; CHECK: ret i32 %1 +; CHECK-NEXT: [[result:%.*]] = select i1 %0, i32 %c, i32 %d +; CHECK-NEXT: ret i32 [[result]] } define i32 @poo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { entry: @@ -49,8 +49,8 @@ entry: %3 = or i32 %1, %2 ret i32 %3 ; CHECK: %0 = icmp slt i32 %a, %b -; CHECK: %1 = select i1 %0, i32 %c, i32 %d -; CHECK: ret i32 %1 +; CHECK-NEXT: [[result:%.*]] = select i1 %0, i32 %c, i32 %d +; CHECK-NEXT: ret i32 [[result]] } define i32 @par(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { @@ -63,6 +63,6 @@ entry: %3 = or i32 %1, %2 ret i32 %3 ; CHECK: %0 = icmp slt i32 %a, %b -; CHECK: %1 = select i1 %0, i32 %c, i32 %d -; CHECK: ret i32 %1 +; CHECK-NEXT: [[result:%.*]] = select i1 %0, i32 %c, i32 %d +; CHECK-NEXT: ret i32 [[result]] } diff --git a/test/Transforms/InstCombine/malloc-free-delete.ll b/test/Transforms/InstCombine/malloc-free-delete.ll index 4e3217dc2d967..cd12b29b1186a 100644 --- a/test/Transforms/InstCombine/malloc-free-delete.ll +++ b/test/Transforms/InstCombine/malloc-free-delete.ll @@ -91,3 +91,32 @@ define void @test5(i8* %ptr, i8** %esc) { store volatile i8 4, i8* %g ret void } + +;; When a basic block contains only a call to free and this block is accessed +;; through a test of the argument of free against null, move the call in the +;; predecessor block. +;; Using simplifycfg will remove the empty basic block and the branch operation +;; Then, performing a dead elimination will remove the comparison. +;; This is what happens with -O1 and upper. +; CHECK: @test6 +define void @test6(i8* %foo) minsize { +; CHECK: %tobool = icmp eq i8* %foo, null +;; Call to free moved +; CHECK-NEXT: tail call void @free(i8* %foo) +; CHECK-NEXT: br i1 %tobool, label %if.end, label %if.then +; CHECK: if.then: +;; Block is now empty and may be simplified by simplifycfg +; CHECK-NEXT: br label %if.end +; CHECK: if.end: +; CHECK-NEXT: ret void +entry: + %tobool = icmp eq i8* %foo, null + br i1 %tobool, label %if.end, label %if.then + +if.then: ; preds = %entry + tail call void @free(i8* %foo) + br label %if.end + +if.end: ; preds = %entry, %if.then + ret void +} diff --git a/test/Transforms/InstCombine/memcmp-1.ll b/test/Transforms/InstCombine/memcmp-1.ll index 4238c5f8fb153..c97b201fc0e94 100644 --- a/test/Transforms/InstCombine/memcmp-1.ll +++ b/test/Transforms/InstCombine/memcmp-1.ll @@ -59,7 +59,7 @@ define i32 @test_simplify5() { %mem2 = getelementptr [4 x i8]* @foo, i32 0, i32 0 %ret = call i32 @memcmp(i8* %mem1, i8* %mem2, i32 3) ret i32 %ret -; CHECK: ret i32 {{[0-9]+}} +; CHECK: ret i32 1 } define i32 @test_simplify6() { @@ -68,5 +68,5 @@ define i32 @test_simplify6() { %mem2 = getelementptr [4 x i8]* @hel, i32 0, i32 0 %ret = call i32 @memcmp(i8* %mem1, i8* %mem2, i32 3) ret i32 %ret -; CHECK: ret i32 {{-[0-9]+}} +; CHECK: ret i32 -1 } diff --git a/test/Transforms/InstCombine/memcpy-from-global.ll b/test/Transforms/InstCombine/memcpy-from-global.ll index 83c893e17dd6d..557b160a8785f 100644 --- a/test/Transforms/InstCombine/memcpy-from-global.ll +++ b/test/Transforms/InstCombine/memcpy-from-global.ll @@ -134,3 +134,13 @@ define void @test8() { ; CHECK: bar ret void } + +define void @test9() { + %A = alloca %U, align 4 + %a = bitcast %U* %A to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%U* getelementptr ([2 x %U]* @H, i64 0, i32 1) to i8*), i64 20, i32 4, i1 false) + call void @bar(i8* %a) readonly +; CHECK: @test9 +; CHECK-NEXT: call void @bar(i8* bitcast (%U* getelementptr inbounds ([2 x %U]* @H, i64 0, i64 1) to i8*)) + ret void +} diff --git a/test/Transforms/InstCombine/mul.ll b/test/Transforms/InstCombine/mul.ll index 6c8e6347634c3..16213b8628ca4 100644 --- a/test/Transforms/InstCombine/mul.ll +++ b/test/Transforms/InstCombine/mul.ll @@ -65,7 +65,7 @@ define i32 @test9(i32 %i) { ; CHECK: @test9 %j = mul i32 %i, -1 ; <i32> [#uses=1] ret i32 %j -; CHECJ: sub i32 0, %i +; CHECK: sub i32 0, %i } define i32 @test10(i32 %a, i32 %b) { @@ -138,10 +138,8 @@ define i32 @test16(i32 %b, i1 %c) { ; e = b & (a >> 31) %e = mul i32 %d, %b ; <i32> [#uses=1] ret i32 %e -; CHECK: [[TEST16:%.*]] = zext i1 %c to i32 -; CHECK-NEXT: %1 = sub i32 0, [[TEST16]] -; CHECK-NEXT: %e = and i32 %1, %b -; CHECK-NEXT: ret i32 %e +; CHECK: [[TEST16:%.*]] = select i1 %c, i32 %b, i32 0 +; CHECK-NEXT: ret i32 [[TEST16]] } ; X * Y (when Y is 0 or 1) --> x & (0-Y) diff --git a/test/Transforms/InstCombine/obfuscated_splat.ll b/test/Transforms/InstCombine/obfuscated_splat.ll index c25dade168a42..fa9cb423d02c8 100644 --- a/test/Transforms/InstCombine/obfuscated_splat.ll +++ b/test/Transforms/InstCombine/obfuscated_splat.ll @@ -1,4 +1,4 @@ -; RUN: opt -instcombine -S %s | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s define void @test(<4 x float> *%in_ptr, <4 x float> *%out_ptr) { %A = load <4 x float>* %in_ptr, align 16 diff --git a/test/Transforms/InstCombine/objsize.ll b/test/Transforms/InstCombine/objsize.ll index 31a3cb46e4595..0ead9d123749c 100644 --- a/test/Transforms/InstCombine/objsize.ll +++ b/test/Transforms/InstCombine/objsize.ll @@ -256,3 +256,131 @@ xpto: return: ret i32 7 } + +declare noalias i8* @valloc(i32) nounwind + +; CHECK: @test14 +; CHECK: ret i32 6 +define i32 @test14(i32 %a) nounwind { + switch i32 %a, label %sw.default [ + i32 1, label %sw.bb + i32 2, label %sw.bb1 + ] + +sw.bb: + %call = tail call noalias i8* @malloc(i32 6) nounwind + br label %sw.epilog + +sw.bb1: + %call2 = tail call noalias i8* @calloc(i32 3, i32 2) nounwind + br label %sw.epilog + +sw.default: + %call3 = tail call noalias i8* @valloc(i32 6) nounwind + br label %sw.epilog + +sw.epilog: + %b.0 = phi i8* [ %call3, %sw.default ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ] + %1 = tail call i32 @llvm.objectsize.i32(i8* %b.0, i1 false) + ret i32 %1 +} + +; CHECK: @test15 +; CHECK: llvm.objectsize +define i32 @test15(i32 %a) nounwind { + switch i32 %a, label %sw.default [ + i32 1, label %sw.bb + i32 2, label %sw.bb1 + ] + +sw.bb: + %call = tail call noalias i8* @malloc(i32 3) nounwind + br label %sw.epilog + +sw.bb1: + %call2 = tail call noalias i8* @calloc(i32 2, i32 1) nounwind + br label %sw.epilog + +sw.default: + %call3 = tail call noalias i8* @valloc(i32 3) nounwind + br label %sw.epilog + +sw.epilog: + %b.0 = phi i8* [ %call3, %sw.default ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ] + %1 = tail call i32 @llvm.objectsize.i32(i8* %b.0, i1 false) + ret i32 %1 +} + +; CHECK: @test16 +; CHECK: llvm.objectsize +define i32 @test16(i8* %a, i32 %n) nounwind { + %b = alloca [5 x i8], align 1 + %c = alloca [5 x i8], align 1 + switch i32 %n, label %sw.default [ + i32 1, label %sw.bb + i32 2, label %sw.bb1 + ] + +sw.bb: + %bp = bitcast [5 x i8]* %b to i8* + br label %sw.epilog + +sw.bb1: + %cp = bitcast [5 x i8]* %c to i8* + br label %sw.epilog + +sw.default: + br label %sw.epilog + +sw.epilog: + %phi = phi i8* [ %a, %sw.default ], [ %cp, %sw.bb1 ], [ %bp, %sw.bb ] + %sz = call i32 @llvm.objectsize.i32(i8* %phi, i1 false) + ret i32 %sz +} + +; CHECK: @test17 +; CHECK: ret i32 5 +define i32 @test17(i32 %n) nounwind { + %b = alloca [5 x i8], align 1 + %c = alloca [5 x i8], align 1 + %bp = bitcast [5 x i8]* %b to i8* + switch i32 %n, label %sw.default [ + i32 1, label %sw.bb + i32 2, label %sw.bb1 + ] + +sw.bb: + br label %sw.epilog + +sw.bb1: + %cp = bitcast [5 x i8]* %c to i8* + br label %sw.epilog + +sw.default: + br label %sw.epilog + +sw.epilog: + %phi = phi i8* [ %bp, %sw.default ], [ %cp, %sw.bb1 ], [ %bp, %sw.bb ] + %sz = call i32 @llvm.objectsize.i32(i8* %phi, i1 false) + ret i32 %sz +} + +@globalalias = alias internal [60 x i8]* @a + +; CHECK: @test18 +; CHECK-NEXT: ret i32 60 +define i32 @test18() { + %bc = bitcast [60 x i8]* @globalalias to i8* + %1 = call i32 @llvm.objectsize.i32(i8* %bc, i1 false) + ret i32 %1 +} + +@globalalias2 = alias weak [60 x i8]* @a + +; CHECK: @test19 +; CHECK: llvm.objectsize +define i32 @test19() { + %bc = bitcast [60 x i8]* @globalalias2 to i8* + %1 = call i32 @llvm.objectsize.i32(i8* %bc, i1 false) + ret i32 %1 +} diff --git a/test/Transforms/InstCombine/or.ll b/test/Transforms/InstCombine/or.ll index c0bb28d15ccf4..bde2a54048add 100644 --- a/test/Transforms/InstCombine/or.ll +++ b/test/Transforms/InstCombine/or.ll @@ -344,10 +344,9 @@ define <4 x i32> @test32(<4 x i1> %and.i1352, <4 x i32> %vecinit6.i176, <4 x i32 %and.i = and <4 x i32> %vecinit6.i191, %neg.i ; <<4 x i32>> [#uses=1] %or.i = or <4 x i32> %and.i, %and.i129 ; <<4 x i32>> [#uses=1] ret <4 x i32> %or.i -; Don't turn this into a vector select until codegen matures to handle them -; better. +; codegen is mature enough to handle vector selects. ; CHECK: @test32 -; CHECK: or <4 x i32> %and.i, %and.i129 +; CHECK: select <4 x i1> %and.i1352, <4 x i32> %vecinit6.i176, <4 x i32> %vecinit6.i191 } define i1 @test33(i1 %X, i1 %Y) { diff --git a/test/Transforms/InstCombine/osx-names.ll b/test/Transforms/InstCombine/osx-names.ll new file mode 100644 index 0000000000000..7b83526aceb50 --- /dev/null +++ b/test/Transforms/InstCombine/osx-names.ll @@ -0,0 +1,30 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s +; <rdar://problem/9815881> +; On OSX x86-32, fwrite and fputs aren't called fwrite and fputs. +; Make sure we use the correct names. + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128" +target triple = "i386-apple-macosx10.7.2" + +%struct.__sFILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 } +%struct.__sbuf = type { i8*, i32 } +%struct.__sFILEX = type opaque + +@.str = private unnamed_addr constant [13 x i8] c"Hello world\0A\00", align 1 +@.str2 = private unnamed_addr constant [3 x i8] c"%s\00", align 1 + +define void @test1(%struct.__sFILE* %stream) nounwind { +; CHECK: define void @test1 +; CHECK: call i32 @"fwrite$UNIX2003" + %call = tail call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %stream, i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0)) nounwind + ret void +} + +define void @test2(%struct.__sFILE* %stream, i8* %str) nounwind ssp { +; CHECK: define void @test2 +; CHECK: call i32 @"fputs$UNIX2003" + %call = tail call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %stream, i8* getelementptr inbounds ([3 x i8]* @.str2, i32 0, i32 0), i8* %str) nounwind + ret void +} + +declare i32 @fprintf(%struct.__sFILE*, i8*, ...) nounwind diff --git a/test/Transforms/InstCombine/pow-1.ll b/test/Transforms/InstCombine/pow-1.ll new file mode 100644 index 0000000000000..8a311f0b74c63 --- /dev/null +++ b/test/Transforms/InstCombine/pow-1.ll @@ -0,0 +1,154 @@ +; Test that the pow library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s +; rdar://7251832 + +; NOTE: The readonly attribute on the pow call should be preserved +; in the cases below where pow is transformed into another function call. + +declare float @powf(float, float) nounwind readonly +declare double @pow(double, double) nounwind readonly + +; Check pow(1.0, x) -> 1.0. + +define float @test_simplify1(float %x) { +; CHECK: @test_simplify1 + %retval = call float @powf(float 1.0, float %x) + ret float %retval +; CHECK-NEXT: ret float 1.000000e+00 +} + +define double @test_simplify2(double %x) { +; CHECK: @test_simplify2 + %retval = call double @pow(double 1.0, double %x) + ret double %retval +; CHECK-NEXT: ret double 1.000000e+00 +} + +; Check pow(2.0, x) -> exp2(x). + +define float @test_simplify3(float %x) { +; CHECK: @test_simplify3 + %retval = call float @powf(float 2.0, float %x) +; CHECK-NEXT: [[EXP2F:%[a-z0-9]+]] = call float @exp2f(float %x) [[NUW_RO:#[0-9]+]] + ret float %retval +; CHECK-NEXT: ret float [[EXP2F]] +} + +define double @test_simplify4(double %x) { +; CHECK: @test_simplify4 + %retval = call double @pow(double 2.0, double %x) +; CHECK-NEXT: [[EXP2:%[a-z0-9]+]] = call double @exp2(double %x) [[NUW_RO]] + ret double %retval +; CHECK-NEXT: ret double [[EXP2]] +} + +; Check pow(x, 0.0) -> 1.0. + +define float @test_simplify5(float %x) { +; CHECK: @test_simplify5 + %retval = call float @powf(float %x, float 0.0) + ret float %retval +; CHECK-NEXT: ret float 1.000000e+00 +} + +define double @test_simplify6(double %x) { +; CHECK: @test_simplify6 + %retval = call double @pow(double %x, double 0.0) + ret double %retval +; CHECK-NEXT: ret double 1.000000e+00 +} + +; Check pow(x, 0.5) -> fabs(sqrt(x)), where x != -infinity. + +define float @test_simplify7(float %x) { +; CHECK: @test_simplify7 + %retval = call float @powf(float %x, float 0.5) +; CHECK-NEXT: [[SQRTF:%[a-z0-9]+]] = call float @sqrtf(float %x) [[NUW_RO]] +; CHECK-NEXT: [[FABSF:%[a-z0-9]+]] = call float @fabsf(float [[SQRTF]]) [[NUW_RO]] +; CHECK-NEXT: [[FCMP:%[a-z0-9]+]] = fcmp oeq float %x, 0xFFF0000000000000 +; CHECK-NEXT: [[SELECT:%[a-z0-9]+]] = select i1 [[FCMP]], float 0x7FF0000000000000, float [[FABSF]] + ret float %retval +; CHECK-NEXT: ret float [[SELECT]] +} + +define double @test_simplify8(double %x) { +; CHECK: @test_simplify8 + %retval = call double @pow(double %x, double 0.5) +; CHECK-NEXT: [[SQRT:%[a-z0-9]+]] = call double @sqrt(double %x) [[NUW_RO]] +; CHECK-NEXT: [[FABS:%[a-z0-9]+]] = call double @fabs(double [[SQRT]]) [[NUW_RO]] +; CHECK-NEXT: [[FCMP:%[a-z0-9]+]] = fcmp oeq double %x, 0xFFF0000000000000 +; CHECK-NEXT: [[SELECT:%[a-z0-9]+]] = select i1 [[FCMP]], double 0x7FF0000000000000, double [[FABS]] + ret double %retval +; CHECK-NEXT: ret double [[SELECT]] +} + +; Check pow(-infinity, 0.5) -> +infinity. + +define float @test_simplify9(float %x) { +; CHECK: @test_simplify9 + %retval = call float @powf(float 0xFFF0000000000000, float 0.5) + ret float %retval +; CHECK-NEXT: ret float 0x7FF0000000000000 +} + +define double @test_simplify10(double %x) { +; CHECK: @test_simplify10 + %retval = call double @pow(double 0xFFF0000000000000, double 0.5) + ret double %retval +; CHECK-NEXT: ret double 0x7FF0000000000000 +} + +; Check pow(x, 1.0) -> x. + +define float @test_simplify11(float %x) { +; CHECK: @test_simplify11 + %retval = call float @powf(float %x, float 1.0) + ret float %retval +; CHECK-NEXT: ret float %x +} + +define double @test_simplify12(double %x) { +; CHECK: @test_simplify12 + %retval = call double @pow(double %x, double 1.0) + ret double %retval +; CHECK-NEXT: ret double %x +} + +; Check pow(x, 2.0) -> x*x. + +define float @test_simplify13(float %x) { +; CHECK: @test_simplify13 + %retval = call float @powf(float %x, float 2.0) +; CHECK-NEXT: [[SQUARE:%[a-z0-9]+]] = fmul float %x, %x + ret float %retval +; CHECK-NEXT: ret float [[SQUARE]] +} + +define double @test_simplify14(double %x) { +; CHECK: @test_simplify14 + %retval = call double @pow(double %x, double 2.0) +; CHECK-NEXT: [[SQUARE:%[a-z0-9]+]] = fmul double %x, %x + ret double %retval +; CHECK-NEXT: ret double [[SQUARE]] +} + +; Check pow(x, -1.0) -> 1.0/x. + +define float @test_simplify15(float %x) { +; CHECK: @test_simplify15 + %retval = call float @powf(float %x, float -1.0) +; CHECK-NEXT: [[RECIPROCAL:%[a-z0-9]+]] = fdiv float 1.000000e+00, %x + ret float %retval +; CHECK-NEXT: ret float [[RECIPROCAL]] +} + +define double @test_simplify16(double %x) { +; CHECK: @test_simplify16 + %retval = call double @pow(double %x, double -1.0) +; CHECK-NEXT: [[RECIPROCAL:%[a-z0-9]+]] = fdiv double 1.000000e+00, %x + ret double %retval +; CHECK-NEXT: ret double [[RECIPROCAL]] +} + +; CHECK: attributes [[NUW_RO]] = { nounwind readonly } diff --git a/test/Transforms/InstCombine/pow-2.ll b/test/Transforms/InstCombine/pow-2.ll new file mode 100644 index 0000000000000..af64cda0904a8 --- /dev/null +++ b/test/Transforms/InstCombine/pow-2.ll @@ -0,0 +1,14 @@ +; Test that the pow library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +declare float @pow(double, double) + +; Check that pow functions with the wrong prototype aren't simplified. + +define float @test_no_simplify1(double %x) { +; CHECK: @test_no_simplify1 + %retval = call float @pow(double 1.0, double %x) +; CHECK-NEXT: call float @pow(double 1.000000e+00, double %x) + ret float %retval +} diff --git a/test/Transforms/InstCombine/pr12338.ll b/test/Transforms/InstCombine/pr12338.ll index 2b5c8f8a74edb..d34600f0fa587 100644 --- a/test/Transforms/InstCombine/pr12338.ll +++ b/test/Transforms/InstCombine/pr12338.ll @@ -1,24 +1,24 @@ ; RUN: opt < %s -instcombine -S | FileCheck %s -define void @entry() nounwind {
-entry:
- br label %for.cond
-
-for.cond:
+define void @entry() nounwind { +entry: + br label %for.cond + +for.cond: %local = phi <1 x i32> [ <i32 0>, %entry ], [ %phi2, %cond.end47 ] -; CHECK: sub <1 x i32> <i32 92>, %local
- %phi3 = sub <1 x i32> zeroinitializer, %local
- br label %cond.end
-
-cond.false:
- br label %cond.end
-
-cond.end:
- %cond = phi <1 x i32> [ %phi3, %for.cond ], [ undef, %cond.false ]
- br label %cond.end47
-
-cond.end47:
- %sum = add <1 x i32> %cond, <i32 92>
- %phi2 = sub <1 x i32> zeroinitializer, %sum
- br label %for.cond
-}
+; CHECK: sub <1 x i32> <i32 92>, %local + %phi3 = sub <1 x i32> zeroinitializer, %local + br label %cond.end + +cond.false: + br label %cond.end + +cond.end: + %cond = phi <1 x i32> [ %phi3, %for.cond ], [ undef, %cond.false ] + br label %cond.end47 + +cond.end47: + %sum = add <1 x i32> %cond, <i32 92> + %phi2 = sub <1 x i32> zeroinitializer, %sum + br label %for.cond +} diff --git a/test/Transforms/InstCombine/printf-1.ll b/test/Transforms/InstCombine/printf-1.ll new file mode 100644 index 0000000000000..3a910ea437b72 --- /dev/null +++ b/test/Transforms/InstCombine/printf-1.ll @@ -0,0 +1,119 @@ +; Test that the printf library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s +; RUN: opt < %s -mtriple xcore-xmos-elf -instcombine -S | FileCheck %s -check-prefix=IPRINTF + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +@hello_world = constant [13 x i8] c"hello world\0A\00" +@h = constant [2 x i8] c"h\00" +@percent = constant [2 x i8] c"%\00" +@percent_c = constant [3 x i8] c"%c\00" +@percent_d = constant [3 x i8] c"%d\00" +@percent_f = constant [3 x i8] c"%f\00" +@percent_s = constant [4 x i8] c"%s\0A\00" +@empty = constant [1 x i8] c"\00" +; CHECK: [[STR:@[a-z0-9]+]] = private unnamed_addr constant [12 x i8] c"hello world\00" + +declare i32 @printf(i8*, ...) + +; Check printf("") -> noop. + +define void @test_simplify1() { +; CHECK: @test_simplify1 + %fmt = getelementptr [1 x i8]* @empty, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt) + ret void +; CHECK-NEXT: ret void +} + +; Check printf("x") -> putchar('x'), even for '%'. + +define void @test_simplify2() { +; CHECK: @test_simplify2 + %fmt = getelementptr [2 x i8]* @h, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt) +; CHECK-NEXT: call i32 @putchar(i32 104) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify3() { +; CHECK: @test_simplify3 + %fmt = getelementptr [2 x i8]* @percent, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt) +; CHECK-NEXT: call i32 @putchar(i32 37) + ret void +; CHECK-NEXT: ret void +} + +; Check printf("foo\n") -> puts("foo"). + +define void @test_simplify4() { +; CHECK: @test_simplify4 + %fmt = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt) +; CHECK-NEXT: call i32 @puts(i8* getelementptr inbounds ([12 x i8]* [[STR]], i32 0, i32 0)) + ret void +; CHECK-NEXT: ret void +} + +; Check printf("%c", chr) -> putchar(chr). + +define void @test_simplify5() { +; CHECK: @test_simplify5 + %fmt = getelementptr [3 x i8]* @percent_c, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt, i8 104) +; CHECK-NEXT: call i32 @putchar(i32 104) + ret void +; CHECK-NEXT: ret void +} + +; Check printf("%s\n", str) -> puts(str). + +define void @test_simplify6() { +; CHECK: @test_simplify6 + %fmt = getelementptr [4 x i8]* @percent_s, i32 0, i32 0 + %str = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt, i8* %str) +; CHECK-NEXT: call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @hello_world, i32 0, i32 0)) + ret void +; CHECK-NEXT: ret void +} + +; Check printf(format, ...) -> iprintf(format, ...) if no floating point. + +define void @test_simplify7() { +; CHECK-IPRINTF: @test_simplify7 + %fmt = getelementptr [3 x i8]* @percent_d, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt, i32 187) +; CHECK-NEXT-IPRINTF: call i32 (i8*, ...)* @iprintf(i8* getelementptr inbounds ([3 x i8]* @percent_d, i32 0, i32 0), i32 187) + ret void +; CHECK-NEXT-IPRINTF: ret void +} + +define void @test_no_simplify1() { +; CHECK-IPRINTF: @test_no_simplify1 + %fmt = getelementptr [3 x i8]* @percent_f, i32 0, i32 0 + call i32 (i8*, ...)* @printf(i8* %fmt, double 1.87) +; CHECK-NEXT-IPRINTF: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) + ret void +; CHECK-NEXT-IPRINTF: ret void +} + +define void @test_no_simplify2(i8* %fmt, double %d) { +; CHECK: @test_no_simplify2 + call i32 (i8*, ...)* @printf(i8* %fmt, double %d) +; CHECK-NEXT: call i32 (i8*, ...)* @printf(i8* %fmt, double %d) + ret void +; CHECK-NEXT: ret void +} + +define i32 @test_no_simplify3() { +; CHECK: @test_no_simplify3 + %fmt = getelementptr [2 x i8]* @h, i32 0, i32 0 + %ret = call i32 (i8*, ...)* @printf(i8* %fmt) +; CHECK-NEXT: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([2 x i8]* @h, i32 0, i32 0)) + ret i32 %ret +; CHECK-NEXT: ret i32 %ret +} diff --git a/test/Transforms/InstCombine/printf-2.ll b/test/Transforms/InstCombine/printf-2.ll new file mode 100644 index 0000000000000..466ee1c757705 --- /dev/null +++ b/test/Transforms/InstCombine/printf-2.ll @@ -0,0 +1,41 @@ +; Test that the printf library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +@hello_world = constant [13 x i8] c"hello world\0A\00" +@h = constant [2 x i8] c"h\00" +@percent_s = constant [4 x i8] c"%s\0A\00" + +declare void @printf(i8*, ...) + +; Check simplification of printf with void return type. + +define void @test_simplify1() { +; CHECK: @test_simplify1 + %fmt = getelementptr [2 x i8]* @h, i32 0, i32 0 + call void (i8*, ...)* @printf(i8* %fmt) +; CHECK-NEXT: call i32 @putchar(i32 104) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify2() { +; CHECK: @test_simplify2 + %fmt = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call void (i8*, ...)* @printf(i8* %fmt) +; CHECK-NEXT: call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @str, i32 0, i32 0)) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify6() { +; CHECK: @test_simplify6 + %fmt = getelementptr [4 x i8]* @percent_s, i32 0, i32 0 + %str = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call void (i8*, ...)* @printf(i8* %fmt, i8* %str) +; CHECK-NEXT: call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @hello_world, i32 0, i32 0)) + ret void +; CHECK-NEXT: ret void +} diff --git a/test/Transforms/InstCombine/ptr-int-cast.ll b/test/Transforms/InstCombine/ptr-int-cast.ll index 9524d449dd8b0..7a6ecff9c0be0 100644 --- a/test/Transforms/InstCombine/ptr-int-cast.ll +++ b/test/Transforms/InstCombine/ptr-int-cast.ll @@ -27,3 +27,34 @@ define i64 @f0(i32 %a0) nounwind { ret i64 %t1 } +define <4 x i32> @test4(<4 x i8*> %arg) nounwind { +; CHECK: @test4 +; CHECK: ptrtoint <4 x i8*> %arg to <4 x i64> +; CHECK: trunc <4 x i64> %1 to <4 x i32> + %p1 = ptrtoint <4 x i8*> %arg to <4 x i32> + ret <4 x i32> %p1 +} + +define <4 x i128> @test5(<4 x i8*> %arg) nounwind { +; CHECK: @test5 +; CHECK: ptrtoint <4 x i8*> %arg to <4 x i64> +; CHECK: zext <4 x i64> %1 to <4 x i128> + %p1 = ptrtoint <4 x i8*> %arg to <4 x i128> + ret <4 x i128> %p1 +} + +define <4 x i8*> @test6(<4 x i32> %arg) nounwind { +; CHECK: @test6 +; CHECK: zext <4 x i32> %arg to <4 x i64> +; CHECK: inttoptr <4 x i64> %1 to <4 x i8*> + %p1 = inttoptr <4 x i32> %arg to <4 x i8*> + ret <4 x i8*> %p1 +} + +define <4 x i8*> @test7(<4 x i128> %arg) nounwind { +; CHECK: @test7 +; CHECK: trunc <4 x i128> %arg to <4 x i64> +; CHECK: inttoptr <4 x i64> %1 to <4 x i8*> + %p1 = inttoptr <4 x i128> %arg to <4 x i8*> + ret <4 x i8*> %p1 +} diff --git a/test/Transforms/InstCombine/puts-1.ll b/test/Transforms/InstCombine/puts-1.ll new file mode 100644 index 0000000000000..ef4e1bbd824c0 --- /dev/null +++ b/test/Transforms/InstCombine/puts-1.ll @@ -0,0 +1,31 @@ +; Test that the puts library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +@empty = constant [1 x i8] zeroinitializer + +declare i32 @puts(i8*) + +; Check puts("") -> putchar('\n'). + +define void @test_simplify1() { +; CHECK: @test_simplify1 + %str = getelementptr [1 x i8]* @empty, i32 0, i32 0 + call i32 @puts(i8* %str) +; CHECK-NEXT: call i32 @putchar(i32 10) + ret void +; CHECK-NEXT: ret void +} + +; Don't simplify if the return value is used. + +define i32 @test_no_simplify1() { +; CHECK: @test_no_simplify1 + %str = getelementptr [1 x i8]* @empty, i32 0, i32 0 + %ret = call i32 @puts(i8* %str) +; CHECK-NEXT: call i32 @puts(i8* getelementptr inbounds ([1 x i8]* @empty, i32 0, i32 0)) + ret i32 %ret +; CHECK-NEXT: ret i32 %ret +} diff --git a/test/Transforms/InstCombine/sdiv-1.ll b/test/Transforms/InstCombine/sdiv-1.ll index c46b5eaef4a87..6ab18ac7f8449 100644 --- a/test/Transforms/InstCombine/sdiv-1.ll +++ b/test/Transforms/InstCombine/sdiv-1.ll @@ -1,6 +1,8 @@ -; RUN: opt < %s -instcombine -inline -S | not grep '-715827882' +; RUN: opt < %s -instcombine -inline -S | FileCheck %s ; PR3142 +; CHECK-NOT: -715827882 + define i32 @a(i32 %X) nounwind readnone { entry: %0 = sub i32 0, %X diff --git a/test/Transforms/InstCombine/sext.ll b/test/Transforms/InstCombine/sext.ll index f1987973f4622..968f37c9c129e 100644 --- a/test/Transforms/InstCombine/sext.ll +++ b/test/Transforms/InstCombine/sext.ll @@ -184,3 +184,12 @@ define i32 @test16(i16 %x) nounwind { ; CHECK-NEXT: %ext = sext i16 %sext to i32 ; CHECK-NEXT: ret i32 %ext } + +define i32 @test17(i1 %x) nounwind { + %c1 = sext i1 %x to i32 + %c2 = sub i32 0, %c1 + ret i32 %c2 +; CHECK: @test17 +; CHECK-NEXT: [[TEST17:%.*]] = zext i1 %x to i32 +; CHECK-NEXT: ret i32 [[TEST17]] +} diff --git a/test/Transforms/InstCombine/shift.ll b/test/Transforms/InstCombine/shift.ll index 25e708b7f51d9..41f8aa9ee8124 100644 --- a/test/Transforms/InstCombine/shift.ll +++ b/test/Transforms/InstCombine/shift.ll @@ -523,9 +523,9 @@ entry: %tmp51 = xor i8 %tmp50, %tmp5 %tmp52 = and i8 %tmp51, -128 %tmp53 = lshr i8 %tmp52, 7 -; CHECK: lshr i8 %tmp51, 7 %tmp54 = mul i8 %tmp53, 16 -; CHECK: shl nuw nsw i8 %tmp53, 4 +; CHECK: %0 = shl i8 %tmp4, 2 +; CHECK: %tmp54 = and i8 %0, 16 %tmp55 = xor i8 %tmp54, %tmp51 ; CHECK: ret i8 %tmp551 ret i8 %tmp55 @@ -659,3 +659,89 @@ define i32 @test53(i32 %x) { ; CHECK-NEXT: %B = shl nuw i32 %x, 2 ; CHECK-NEXT: ret i32 %B } + +define i32 @test54(i32 %x) { + %shr2 = lshr i32 %x, 1 + %shl = shl i32 %shr2, 4 + %and = and i32 %shl, 16 + ret i32 %and +; CHECK: @test54 +; CHECK: shl i32 %x, 3 +} + + +define i32 @test55(i32 %x) { + %shr2 = lshr i32 %x, 1 + %shl = shl i32 %shr2, 4 + %or = or i32 %shl, 8 + ret i32 %or +; CHECK: @test55 +; CHECK: shl i32 %x, 3 +} + +define i32 @test56(i32 %x) { + %shr2 = lshr i32 %x, 1 + %shl = shl i32 %shr2, 4 + %or = or i32 %shl, 7 + ret i32 %or +; CHECK: @test56 +; CHECK: shl i32 %shr2, 4 +} + + +define i32 @test57(i32 %x) { + %shr = lshr i32 %x, 1 + %shl = shl i32 %shr, 4 + %and = and i32 %shl, 16 + ret i32 %and +; CHECK: @test57 +; CHECK: shl i32 %x, 3 +} + +define i32 @test58(i32 %x) { + %shr = lshr i32 %x, 1 + %shl = shl i32 %shr, 4 + %or = or i32 %shl, 8 + ret i32 %or +; CHECK: @test58 +; CHECK: shl i32 %x, 3 +} + +define i32 @test59(i32 %x) { + %shr = ashr i32 %x, 1 + %shl = shl i32 %shr, 4 + %or = or i32 %shl, 7 + ret i32 %or +; CHECK: @test59 +; CHECK: %shl = shl i32 %shr1, 4 +} + + +define i32 @test60(i32 %x) { + %shr = ashr i32 %x, 4 + %shl = shl i32 %shr, 1 + %or = or i32 %shl, 1 + ret i32 %or +; CHECK: @test60 +; CHECK: ashr i32 %x, 3 +} + + +define i32 @test61(i32 %x) { + %shr = ashr i32 %x, 4 + %shl = shl i32 %shr, 1 + %or = or i32 %shl, 2 + ret i32 %or +; CHECK: @test61 +; CHECK: ashr i32 %x, 4 +} + +; propagate "exact" trait +define i32 @test62(i32 %x) { + %shr = ashr exact i32 %x, 4 + %shl = shl i32 %shr, 1 + %or = or i32 %shl, 1 + ret i32 %or +; CHECK: @test62 +; CHECK: ashr exact i32 %x, 3 +} diff --git a/test/Transforms/InstCombine/signext.ll b/test/Transforms/InstCombine/signext.ll index ecee9830cd576..5ed1cd5590ae9 100644 --- a/test/Transforms/InstCombine/signext.ll +++ b/test/Transforms/InstCombine/signext.ll @@ -82,6 +82,6 @@ entry: %sub = add i32 %xor, -67108864 ; <i32> [#uses=1] ret i32 %sub ; CHECK: @test8 -; CHECK: %shr = ashr i32 %x, 5 -; CHECK: ret i32 %shr +; CHECK: %sub = ashr i32 %x, 5 +; CHECK: ret i32 %sub } diff --git a/test/Transforms/InstCombine/sink_instruction.ll b/test/Transforms/InstCombine/sink_instruction.ll index e521de208f216..5c4019a98df55 100644 --- a/test/Transforms/InstCombine/sink_instruction.ll +++ b/test/Transforms/InstCombine/sink_instruction.ll @@ -1,4 +1,4 @@ -; RUN: opt -instcombine %s -S | FileCheck %s +; RUN: opt -instcombine -S < %s | FileCheck %s ;; This tests that the instructions in the entry blocks are sunk into each ;; arm of the 'if'. diff --git a/test/Transforms/InstCombine/sprintf-1.ll b/test/Transforms/InstCombine/sprintf-1.ll new file mode 100644 index 0000000000000..9b8c8b1b12c7b --- /dev/null +++ b/test/Transforms/InstCombine/sprintf-1.ll @@ -0,0 +1,100 @@ +; Test that the sprintf library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s +; RUN: opt < %s -mtriple xcore-xmos-elf -instcombine -S | FileCheck %s -check-prefix=IPRINTF + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +@hello_world = constant [13 x i8] c"hello world\0A\00" +@null = constant [1 x i8] zeroinitializer +@null_hello = constant [7 x i8] c"\00hello\00" +@h = constant [2 x i8] c"h\00" +@percent_c = constant [3 x i8] c"%c\00" +@percent_d = constant [3 x i8] c"%d\00" +@percent_f = constant [3 x i8] c"%f\00" +@percent_s = constant [3 x i8] c"%s\00" + +declare i32 @sprintf(i8*, i8*, ...) + +; Check sprintf(dst, fmt) -> llvm.memcpy(str, fmt, strlen(fmt) + 1, 1). + +define void @test_simplify1(i8* %dst) { +; CHECK: @test_simplify1 + %fmt = getelementptr [13 x i8]* @hello_world, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* getelementptr inbounds ([13 x i8]* @hello_world, i32 0, i32 0), i32 13, i32 1, i1 false) + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify2(i8* %dst) { +; CHECK: @test_simplify2 + %fmt = getelementptr [1 x i8]* @null, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt) +; CHECK-NEXT: store i8 0, i8* %dst, align 1 + ret void +; CHECK-NEXT: ret void +} + +define void @test_simplify3(i8* %dst) { +; CHECK: @test_simplify3 + %fmt = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt) +; CHECK-NEXT: store i8 0, i8* %dst, align 1 + ret void +; CHECK-NEXT: ret void +} + +; Check sprintf(dst, "%c", chr) -> *(i8*)dst = chr; *((i8*)dst + 1) = 0. + +define void @test_simplify4(i8* %dst) { +; CHECK: @test_simplify4 + %fmt = getelementptr [3 x i8]* @percent_c, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt, i8 104) +; CHECK-NEXT: store i8 104, i8* %dst, align 1 +; CHECK-NEXT: [[NUL:%[a-z0-9]+]] = getelementptr i8* %dst, i32 1 +; CHECK-NEXT: store i8 0, i8* [[NUL]], align 1 + ret void +; CHECK-NEXT: ret void +} + +; Check sprintf(dst, "%s", str) -> llvm.memcpy(dest, str, strlen(str) + 1, 1). + +define void @test_simplify5(i8* %dst, i8* %str) { +; CHECK: @test_simplify5 + %fmt = getelementptr [3 x i8]* @percent_s, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt, i8* %str) +; CHECK-NEXT: [[STRLEN:%[a-z0-9]+]] = call i32 @strlen(i8* %str) +; CHECK-NEXT: [[LENINC:%[a-z0-9]+]] = add i32 [[STRLEN]], 1 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %str, i32 [[LENINC]], i32 1, i1 false) + ret void +; CHECK-NEXT: ret void +} + +; Check sprintf(dst, format, ...) -> siprintf(str, format, ...) if no floating. + +define void @test_simplify6(i8* %dst) { +; CHECK-IPRINTF: @test_simplify6 + %fmt = getelementptr [3 x i8]* @percent_d, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt, i32 187) +; CHECK-NEXT-IPRINTF: call i32 (i8*, i8*, ...)* @siprintf(i8* %dst, i8* getelementptr inbounds ([3 x i8]* @percent_d, i32 0, i32 0), i32 187) + ret void +; CHECK-NEXT-IPRINTF: ret void +} + +define void @test_no_simplify1(i8* %dst) { +; CHECK-IPRINTF: @test_no_simplify1 + %fmt = getelementptr [3 x i8]* @percent_f, i32 0, i32 0 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt, double 1.87) +; CHECK-NEXT-IPRINTF: call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* getelementptr inbounds ([3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) + ret void +; CHECK-NEXT-IPRINTF: ret void +} + +define void @test_no_simplify2(i8* %dst, i8* %fmt, double %d) { +; CHECK: @test_no_simplify2 + call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt, double %d) +; CHECK-NEXT: call i32 (i8*, i8*, ...)* @sprintf(i8* %dst, i8* %fmt, double %d) + ret void +; CHECK-NEXT: ret void +} diff --git a/test/Transforms/InstCombine/sqrt.ll b/test/Transforms/InstCombine/sqrt.ll index cc78417ebbd68..440b9748518dd 100644 --- a/test/Transforms/InstCombine/sqrt.ll +++ b/test/Transforms/InstCombine/sqrt.ll @@ -1,4 +1,4 @@ -; RUN: opt -S -instcombine %s | FileCheck %s +; RUN: opt -S -instcombine < %s | FileCheck %s define float @test1(float %x) nounwind readnone ssp { entry: diff --git a/test/Transforms/InstCombine/store.ll b/test/Transforms/InstCombine/store.ll index 64460d7a6d610..164ba7632684b 100644 --- a/test/Transforms/InstCombine/store.ll +++ b/test/Transforms/InstCombine/store.ll @@ -83,3 +83,37 @@ Cont: ; CHECK-NEXT: ret void } + +; PR14753 - merging two stores should preserve the TBAA tag. +define void @test6(i32 %n, float* %a, i32* %gi) nounwind uwtable ssp { +entry: + store i32 42, i32* %gi, align 4, !tbaa !0 + br label %for.cond + +for.cond: ; preds = %for.body, %entry + %storemerge = phi i32 [ 0, %entry ], [ %inc, %for.body ] + %0 = load i32* %gi, align 4, !tbaa !0 + %cmp = icmp slt i32 %0, %n + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + %idxprom = sext i32 %0 to i64 + %arrayidx = getelementptr inbounds float* %a, i64 %idxprom + store float 0.000000e+00, float* %arrayidx, align 4, !tbaa !3 + %1 = load i32* %gi, align 4, !tbaa !0 + %inc = add nsw i32 %1, 1 + store i32 %inc, i32* %gi, align 4, !tbaa !0 + br label %for.cond + +for.end: ; preds = %for.cond + ret void +; CHECK: @test6 +; CHECK: for.cond: +; CHECK-NEXT: phi i32 [ 42 +; CHECK-NEXT: store i32 %storemerge, i32* %gi, align 4, !tbaa !0 +} + +!0 = metadata !{metadata !"int", metadata !1} +!1 = metadata !{metadata !"omnipotent char", metadata !2} +!2 = metadata !{metadata !"Simple C/C++ TBAA"} +!3 = metadata !{metadata !"float", metadata !1} diff --git a/test/Transforms/InstCombine/strto-1.ll b/test/Transforms/InstCombine/strto-1.ll index 16c0c67970db8..7139972fe0432 100644 --- a/test/Transforms/InstCombine/strto-1.ll +++ b/test/Transforms/InstCombine/strto-1.ll @@ -1,29 +1,29 @@ ; Test that the strto* library call simplifiers works correctly. ; -; RUN: opt < %s -instcombine -S | FileCheck %s +; RUN: opt < %s -instcombine -functionattrs -S | FileCheck %s target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" declare i64 @strtol(i8* %s, i8** %endptr, i32 %base) -; CHECK: declare i64 @strtol(i8*, i8**, i32) +; CHECK: declare i64 @strtol(i8*, i8** nocapture, i32) declare double @strtod(i8* %s, i8** %endptr, i32 %base) -; CHECK: declare double @strtod(i8*, i8**, i32) +; CHECK: declare double @strtod(i8*, i8** nocapture, i32) declare float @strtof(i8* %s, i8** %endptr, i32 %base) -; CHECK: declare float @strtof(i8*, i8**, i32) +; CHECK: declare float @strtof(i8*, i8** nocapture, i32) declare i64 @strtoul(i8* %s, i8** %endptr, i32 %base) -; CHECK: declare i64 @strtoul(i8*, i8**, i32) +; CHECK: declare i64 @strtoul(i8*, i8** nocapture, i32) declare i64 @strtoll(i8* %s, i8** %endptr, i32 %base) -; CHECK: declare i64 @strtoll(i8*, i8**, i32) +; CHECK: declare i64 @strtoll(i8*, i8** nocapture, i32) declare double @strtold(i8* %s, i8** %endptr) -; CHECK: declare double @strtold(i8*, i8**) +; CHECK: declare double @strtold(i8*, i8** nocapture) declare i64 @strtoull(i8* %s, i8** %endptr, i32 %base) -; CHECK: declare i64 @strtoull(i8*, i8**, i32) +; CHECK: declare i64 @strtoull(i8*, i8** nocapture, i32) define void @test_simplify1(i8* %x, i8** %endptr) { ; CHECK: @test_simplify1 diff --git a/test/Transforms/InstCombine/toascii-1.ll b/test/Transforms/InstCombine/toascii-1.ll new file mode 100644 index 0000000000000..c4a13e2293937 --- /dev/null +++ b/test/Transforms/InstCombine/toascii-1.ll @@ -0,0 +1,59 @@ +; Test that the toascii library call simplifier works correctly. +; +; RUN: opt < %s -instcombine -S | FileCheck %s + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare i32 @toascii(i32) + +; Check isascii(c) -> c & 0x7f. + +define i32 @test_simplify1() { +; CHECK: @test_simplify1 + %ret = call i32 @toascii(i32 0) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify2() { +; CHECK: @test_simplify2 + %ret = call i32 @toascii(i32 1) + ret i32 %ret +; CHECK-NEXT: ret i32 1 +} + +define i32 @test_simplify3() { +; CHECK: @test_simplify3 + %ret = call i32 @toascii(i32 127) + ret i32 %ret +; CHECK-NEXT: ret i32 127 +} + +define i32 @test_simplify4() { +; CHECK: @test_simplify4 + %ret = call i32 @toascii(i32 128) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify5() { +; CHECK: @test_simplify5 + %ret = call i32 @toascii(i32 255) + ret i32 %ret +; CHECK-NEXT: ret i32 127 +} + +define i32 @test_simplify6() { +; CHECK: @test_simplify6 + %ret = call i32 @toascii(i32 256) + ret i32 %ret +; CHECK-NEXT: ret i32 0 +} + +define i32 @test_simplify7(i32 %x) { +; CHECK: @test_simplify7 + %ret = call i32 @toascii(i32 %x) +; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, 127 + ret i32 %ret +; CHECK-NEXT: ret i32 [[AND]] +} diff --git a/test/Transforms/InstCombine/vec_extract_elt.ll b/test/Transforms/InstCombine/vec_extract_elt.ll index 63e4ee2112d81..166066a201bf6 100644 --- a/test/Transforms/InstCombine/vec_extract_elt.ll +++ b/test/Transforms/InstCombine/vec_extract_elt.ll @@ -7,3 +7,13 @@ define i32 @test(float %f) { ret i32 %tmp19 } +define i64 @test2(i64 %in) { + %vec = insertelement <8 x i64> undef, i64 %in, i32 0 + %splat = shufflevector <8 x i64> %vec, <8 x i64> undef, <8 x i32> zeroinitializer + %add = add <8 x i64> %splat, <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7> + %scl1 = extractelement <8 x i64> %add, i32 0 + %scl2 = extractelement <8 x i64> %add, i32 0 + %r = add i64 %scl1, %scl2 + ret i64 %r +} + diff --git a/test/Transforms/InstCombine/vector-casts.ll b/test/Transforms/InstCombine/vector-casts.ll index 7bbf53c270f48..2f2990b7b0555 100644 --- a/test/Transforms/InstCombine/vector-casts.ll +++ b/test/Transforms/InstCombine/vector-casts.ll @@ -64,7 +64,8 @@ entry: ; CHECK: @test5 ; CHECK: sext <4 x i1> %cmp to <4 x i32> -; CHECK: sext <4 x i1> %cmp4 to <4 x i32> +; The sext-and pair is canonicalized to a select. +; CHECK: select <4 x i1> %cmp4, <4 x i32> %sext, <4 x i32> zeroinitializer } diff --git a/test/Transforms/InstCombine/vector-type.ll b/test/Transforms/InstCombine/vector-type.ll new file mode 100644 index 0000000000000..59a4bdd19e70a --- /dev/null +++ b/test/Transforms/InstCombine/vector-type.ll @@ -0,0 +1,15 @@ +; The code in InstCombiner::FoldSelectOpOp was calling +; Type::getVectorNumElements without checking first if the type was a vector. + +; RUN: opt < %s -instcombine -S + +define i32 @vselect1(i32 %a.coerce, i32 %b.coerce, i32 %c.coerce) { +entry: + %0 = bitcast i32 %a.coerce to <2 x i16> + %1 = bitcast i32 %b.coerce to <2 x i16> + %2 = bitcast i32 %c.coerce to <2 x i16> + %cmp = icmp sge <2 x i16> %2, zeroinitializer + %or = select <2 x i1> %cmp, <2 x i16> %0, <2 x i16> %1 + %3 = bitcast <2 x i16> %or to i32 + ret i32 %3 +} diff --git a/test/Transforms/InstCombine/vector_gep1.ll b/test/Transforms/InstCombine/vector_gep1.ll index 6523622995622..90ca26212f2a6 100644 --- a/test/Transforms/InstCombine/vector_gep1.ll +++ b/test/Transforms/InstCombine/vector_gep1.ll @@ -1,5 +1,5 @@ -; RUN: opt -instcombine %s -disable-output -; RUN: opt -instsimplify %s -disable-output +; RUN: opt -instcombine -disable-output < %s +; RUN: opt -instsimplify -disable-output < %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" @@ -35,3 +35,8 @@ define <2 x i1> @test5(<2 x i8*> %a) { %B = icmp ult <2 x i8*> %g, zeroinitializer ret <2 x i1> %B } + +define <2 x i32*> @test7(<2 x {i32, i32}*> %a) { + %w = getelementptr <2 x {i32, i32}*> %a, <2 x i32> <i32 5, i32 9>, <2 x i32> zeroinitializer + ret <2 x i32*> %w +} diff --git a/test/Transforms/InstCombine/xor2.ll b/test/Transforms/InstCombine/xor2.ll index 89f00bd684757..be06d7999d841 100644 --- a/test/Transforms/InstCombine/xor2.ll +++ b/test/Transforms/InstCombine/xor2.ll @@ -51,3 +51,34 @@ define i32 @test4(i32 %A, i32 %B) { ; CHECK: %1 = ashr i32 %A, %B ; CHECK: ret i32 %1 } + +; defect-2 in rdar://12329730 +; (X^C1) >> C2) ^ C3 -> (X>>C2) ^ ((C1>>C2)^C3) +; where the "X" has more than one use +define i32 @test5(i32 %val1) { +test5: + %xor = xor i32 %val1, 1234 + %shr = lshr i32 %xor, 8 + %xor1 = xor i32 %shr, 1 + %add = add i32 %xor1, %xor + ret i32 %add +; CHECK: @test5 +; CHECK: lshr i32 %val1, 8 +; CHECK: ret +} + +; defect-1 in rdar://12329730 +; Simplify (X^Y) -> X or Y in the user's context if we know that +; only bits from X or Y are demanded. +; e.g. the "x ^ 1234" can be optimized into x in the context of "t >> 16". +; Put in other word, t >> 16 -> x >> 16. +; unsigned foo(unsigned x) { unsigned t = x ^ 1234; ; return (t >> 16) + t;} +define i32 @test6(i32 %x) { + %xor = xor i32 %x, 1234 + %shr = lshr i32 %xor, 16 + %add = add i32 %shr, %xor + ret i32 %add +; CHECK: @test6 +; CHECK: lshr i32 %x, 16 +; CHECK: ret +} diff --git a/test/Transforms/InstCombine/zext-bool-add-sub.ll b/test/Transforms/InstCombine/zext-bool-add-sub.ll index 78bcedbbc2e1a..b5310575502bd 100644 --- a/test/Transforms/InstCombine/zext-bool-add-sub.ll +++ b/test/Transforms/InstCombine/zext-bool-add-sub.ll @@ -4,9 +4,9 @@ define i32 @a(i1 zeroext %x, i1 zeroext %y) { entry: ; CHECK: @a -; CHECK: [[TMP1:%.*]] = zext i1 %y to i32 +; CHECK: [[TMP1:%.*]] = sext i1 %y to i32 ; CHECK: [[TMP2:%.*]] = select i1 %x, i32 2, i32 1 -; CHECK-NEXT: sub i32 [[TMP2]], [[TMP1]] +; CHECK-NEXT: add i32 [[TMP2]], [[TMP1]] %conv = zext i1 %x to i32 %conv3 = zext i1 %y to i32 %conv3.neg = sub i32 0, %conv3 |