aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/InstSimplify
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/InstSimplify')
-rw-r--r--test/Transforms/InstSimplify/AndOrXor.ll55
-rw-r--r--test/Transforms/InstSimplify/compare.ll64
-rw-r--r--test/Transforms/InstSimplify/fast-math.ll9
-rw-r--r--test/Transforms/InstSimplify/floating-point-arithmetic.ll26
-rw-r--r--test/Transforms/InstSimplify/floating-point-compare.ll60
-rw-r--r--test/Transforms/InstSimplify/load.ll19
-rw-r--r--test/Transforms/InstSimplify/noalias-ptr.ll259
-rw-r--r--test/Transforms/InstSimplify/select.ll161
-rw-r--r--test/Transforms/InstSimplify/undef.ll105
9 files changed, 758 insertions, 0 deletions
diff --git a/test/Transforms/InstSimplify/AndOrXor.ll b/test/Transforms/InstSimplify/AndOrXor.ll
index 8ed06e8..ce3c2aa 100644
--- a/test/Transforms/InstSimplify/AndOrXor.ll
+++ b/test/Transforms/InstSimplify/AndOrXor.ll
@@ -148,3 +148,58 @@ define i1 @or_of_icmps5(i32 %b) {
ret i1 %cmp
; CHECK: ret i1 true
}
+
+define i32 @neg_nuw(i32 %x) {
+; CHECK-LABEL: @neg_nuw(
+ %neg = sub nuw i32 0, %x
+ ret i32 %neg
+; CHECK: ret i32 0
+}
+
+define i1 @and_icmp1(i32 %x, i32 %y) {
+ %1 = icmp ult i32 %x, %y
+ %2 = icmp ne i32 %y, 0
+ %3 = and i1 %1, %2
+ ret i1 %3
+}
+; CHECK-LABEL: @and_icmp1(
+; CHECK: %[[cmp:.*]] = icmp ult i32 %x, %y
+; CHECK: ret i1 %[[cmp]]
+
+define i1 @and_icmp2(i32 %x, i32 %y) {
+ %1 = icmp ult i32 %x, %y
+ %2 = icmp eq i32 %y, 0
+ %3 = and i1 %1, %2
+ ret i1 %3
+}
+; CHECK-LABEL: @and_icmp2(
+; CHECK: ret i1 false
+
+define i1 @or_icmp1(i32 %x, i32 %y) {
+ %1 = icmp ult i32 %x, %y
+ %2 = icmp ne i32 %y, 0
+ %3 = or i1 %1, %2
+ ret i1 %3
+}
+; CHECK-LABEL: @or_icmp1(
+; CHECK: %[[cmp:.*]] = icmp ne i32 %y, 0
+; CHECK: ret i1 %[[cmp]]
+
+define i1 @or_icmp2(i32 %x, i32 %y) {
+ %1 = icmp uge i32 %x, %y
+ %2 = icmp ne i32 %y, 0
+ %3 = or i1 %1, %2
+ ret i1 %3
+}
+; CHECK-LABEL: @or_icmp2(
+; CHECK: ret i1 true
+
+define i1 @or_icmp3(i32 %x, i32 %y) {
+ %1 = icmp uge i32 %x, %y
+ %2 = icmp eq i32 %y, 0
+ %3 = or i1 %1, %2
+ ret i1 %3
+}
+; CHECK-LABEL: @or_icmp3(
+; CHECK: %[[cmp:.*]] = icmp uge i32 %x, %y
+; CHECK: ret i1 %[[cmp]]
diff --git a/test/Transforms/InstSimplify/compare.ll b/test/Transforms/InstSimplify/compare.ll
index 38fd747..10c7ca6 100644
--- a/test/Transforms/InstSimplify/compare.ll
+++ b/test/Transforms/InstSimplify/compare.ll
@@ -1100,3 +1100,67 @@ define i1 @icmp_shl_1_V_ne_31(i32 %V) {
; CHECK-LABEL: @icmp_shl_1_V_ne_31(
; CHECK-NEXT: ret i1 true
}
+
+define i1 @tautological1(i32 %A, i32 %B) {
+ %C = and i32 %A, %B
+ %D = icmp ugt i32 %C, %A
+ ret i1 %D
+; CHECK-LABEL: @tautological1(
+; CHECK: ret i1 false
+}
+
+define i1 @tautological2(i32 %A, i32 %B) {
+ %C = and i32 %A, %B
+ %D = icmp ule i32 %C, %A
+ ret i1 %D
+; CHECK-LABEL: @tautological2(
+; CHECK: ret i1 true
+}
+
+define i1 @tautological3(i32 %A, i32 %B) {
+ %C = or i32 %A, %B
+ %D = icmp ule i32 %A, %C
+ ret i1 %D
+; CHECK-LABEL: @tautological3(
+; CHECK: ret i1 true
+}
+
+define i1 @tautological4(i32 %A, i32 %B) {
+ %C = or i32 %A, %B
+ %D = icmp ugt i32 %A, %C
+ ret i1 %D
+; CHECK-LABEL: @tautological4(
+; CHECK: ret i1 false
+}
+
+define i1 @tautological5(i32 %A, i32 %B) {
+ %C = or i32 %A, %B
+ %D = icmp ult i32 %C, %A
+ ret i1 %D
+; CHECK-LABEL: @tautological5(
+; CHECK: ret i1 false
+}
+
+define i1 @tautological6(i32 %A, i32 %B) {
+ %C = or i32 %A, %B
+ %D = icmp uge i32 %C, %A
+ ret i1 %D
+; CHECK-LABEL: @tautological6(
+; CHECK: ret i1 true
+}
+
+define i1 @tautological7(i32 %A, i32 %B) {
+ %C = and i32 %A, %B
+ %D = icmp uge i32 %A, %C
+ ret i1 %D
+; CHECK-LABEL: @tautological7(
+; CHECK: ret i1 true
+}
+
+define i1 @tautological8(i32 %A, i32 %B) {
+ %C = and i32 %A, %B
+ %D = icmp ult i32 %A, %C
+ ret i1 %D
+; CHECK-LABEL: @tautological8(
+; CHECK: ret i1 false
+}
diff --git a/test/Transforms/InstSimplify/fast-math.ll b/test/Transforms/InstSimplify/fast-math.ll
index 71d1ed8..e7fb14d 100644
--- a/test/Transforms/InstSimplify/fast-math.ll
+++ b/test/Transforms/InstSimplify/fast-math.ll
@@ -105,3 +105,12 @@ define float @nofold_fadd_x_0(float %a) {
; CHECK: ret float %no_zero
ret float %no_zero
}
+
+; fdiv nsz nnan 0, X ==> 0
+define double @fdiv_zero_by_x(double %X) {
+; CHECK-LABEL: @fdiv_zero_by_x(
+; 0 / X -> 0
+ %r = fdiv nnan nsz double 0.0, %X
+ ret double %r
+; CHECK: ret double 0
+}
diff --git a/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index 8177440..b0957a8 100644
--- a/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -33,3 +33,29 @@ define double @fmul_X_1(double %a) {
; CHECK: ret double %a
ret double %b
}
+
+; We can't optimize away the fadd in this test because the input
+; value to the function and subsequently to the fadd may be -0.0.
+; In that one special case, the result of the fadd should be +0.0
+; rather than the first parameter of the fadd.
+
+; Fragile test warning: We need 6 sqrt calls to trigger the bug
+; because the internal logic has a magic recursion limit of 6.
+; This is presented without any explanation or ability to customize.
+
+declare float @sqrtf(float)
+
+define float @PR22688(float %x) {
+ %1 = call float @sqrtf(float %x)
+ %2 = call float @sqrtf(float %1)
+ %3 = call float @sqrtf(float %2)
+ %4 = call float @sqrtf(float %3)
+ %5 = call float @sqrtf(float %4)
+ %6 = call float @sqrtf(float %5)
+ %7 = fadd float %6, 0.0
+ ret float %7
+
+; CHECK-LABEL: @PR22688(
+; CHECK: fadd float %6, 0.0
+}
+
diff --git a/test/Transforms/InstSimplify/floating-point-compare.ll b/test/Transforms/InstSimplify/floating-point-compare.ll
new file mode 100644
index 0000000..af48d06
--- /dev/null
+++ b/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -0,0 +1,60 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+; These tests choose arbitrarily between float and double,
+; and between uge and olt, to give reasonble coverage
+; without combinatorial explosion.
+
+declare float @llvm.fabs.f32(float)
+declare float @llvm.sqrt.f32(float)
+declare double @llvm.powi.f64(double,i32)
+declare float @llvm.exp.f32(float)
+declare double @llvm.exp2.f64(double)
+declare float @llvm.fma.f32(float,float,float)
+
+declare void @expect_equal(i1,i1)
+
+; CHECK-LABEL: @orderedLessZeroTree(
+define i1 @orderedLessZeroTree(float,float,float,float) {
+ %square = fmul float %0, %0
+ %abs = call float @llvm.fabs.f32(float %1)
+ %sqrt = call float @llvm.sqrt.f32(float %2)
+ %fma = call float @llvm.fma.f32(float %3, float %3, float %sqrt)
+ %div = fdiv float %square, %abs
+ %rem = frem float %sqrt, %fma
+ %add = fadd float %div, %rem
+ %uge = fcmp uge float %add, 0.000000e+00
+; CHECK: ret i1 true
+ ret i1 %uge
+}
+
+; CHECK-LABEL: @orderedLessZeroExpExt(
+define i1 @orderedLessZeroExpExt(float) {
+ %a = call float @llvm.exp.f32(float %0)
+ %b = fpext float %a to double
+ %uge = fcmp uge double %b, 0.000000e+00
+; CHECK: ret i1 true
+ ret i1 %uge
+}
+
+; CHECK-LABEL: @orderedLessZeroExp2Trunc(
+define i1 @orderedLessZeroExp2Trunc(double) {
+ %a = call double @llvm.exp2.f64(double %0)
+ %b = fptrunc double %a to float
+ %olt = fcmp olt float %b, 0.000000e+00
+; CHECK: ret i1 false
+ ret i1 %olt
+}
+
+; CHECK-LABEL: @orderedLessZeroPowi(
+define i1 @orderedLessZeroPowi(double,double) {
+ ; Even constant exponent
+ %a = call double @llvm.powi.f64(double %0, i32 2)
+ %square = fmul double %1, %1
+ ; Odd constant exponent with provably non-negative base
+ %b = call double @llvm.powi.f64(double %square, i32 3)
+ %c = fadd double %a, %b
+ %olt = fcmp olt double %b, 0.000000e+00
+; CHECK: ret i1 false
+ ret i1 %olt
+}
+
diff --git a/test/Transforms/InstSimplify/load.ll b/test/Transforms/InstSimplify/load.ll
new file mode 100644
index 0000000..92953cd
--- /dev/null
+++ b/test/Transforms/InstSimplify/load.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+@zeroinit = constant {} zeroinitializer
+@undef = constant {} undef
+
+define i32 @crash_on_zeroinit() {
+; CHECK-LABEL: @crash_on_zeroinit
+; CHECK: ret i32 0
+ %load = load i32* bitcast ({}* @zeroinit to i32*)
+ ret i32 %load
+}
+
+define i32 @crash_on_undef() {
+; CHECK-LABEL: @crash_on_undef
+; CHECK: ret i32 undef
+ %load = load i32* bitcast ({}* @undef to i32*)
+ ret i32 %load
+}
+
diff --git a/test/Transforms/InstSimplify/noalias-ptr.ll b/test/Transforms/InstSimplify/noalias-ptr.ll
new file mode 100644
index 0000000..7693e55
--- /dev/null
+++ b/test/Transforms/InstSimplify/noalias-ptr.ll
@@ -0,0 +1,259 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@g1 = global i32 0, align 4
+@g2 = internal global i32 0, align 4
+@g3 = unnamed_addr global i32 0, align 4
+@g4 = hidden global i32 0, align 4
+@g5 = protected global i32 0, align 4
+@g6 = thread_local unnamed_addr global i32 0, align 4
+
+; Make sure we can simplify away a pointer comparison between
+; dynamically-allocated memory and a local stack allocation.
+; void p()
+; {
+; int *mData;
+; int mStackData[10];
+; mData = new int[12];
+; if (mData != mStackData) {
+; delete[] mData;
+; }
+; }
+
+define void @_Z2p1v() #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = tail call noalias i8* @_Znam(i64 48) #4
+ %3 = bitcast i8* %2 to i32*
+ %4 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %5 = icmp eq i32* %3, %4
+ br i1 %5, label %7, label %6
+
+; CHECK-LABEL: @_Z2p1v
+; CHECK-NOT: icmp
+; CHECK: ret void
+
+; <label>:6 ; preds = %0
+ call void @_ZdaPv(i8* %2) #5
+ br label %7
+
+; <label>:7 ; preds = %0, %6
+ ret void
+}
+
+; Also check a more-complicated case with multiple underlying objects.
+
+define void @_Z2p2bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* @g2
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z2p2bb
+; CHECK-NOT: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+define void @_Z2p4bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* @g3
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z2p4bb
+; CHECK-NOT: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+define void @_Z2p5bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* @g4
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z2p5bb
+; CHECK-NOT: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+define void @_Z2p6bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* @g5
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z2p6bb
+; CHECK-NOT: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+; Here's another case involving multiple underlying objects, but this time we
+; must keep the comparison (it might involve a regular pointer-typed function
+; argument).
+
+define void @_Z4nopebbPi(i1 zeroext %b1, i1 zeroext %b2, i32* readnone %q) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* %q
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z4nopebbPi
+; CHECK: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+define void @_Z2p3bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* @g1
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z2p3bb
+; CHECK: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+define void @_Z2p7bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
+ %mStackData = alloca [10 x i32], align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %3 = select i1 %b1, i32* %2, i32* @g6
+ %4 = tail call noalias i8* @_Znam(i64 48) #4
+ %5 = tail call noalias i8* @_Znam(i64 48) #4
+ %.v = select i1 %b2, i8* %4, i8* %5
+ %6 = bitcast i8* %.v to i32*
+ %7 = icmp eq i32* %6, %3
+ br i1 %7, label %9, label %8
+
+; CHECK-LABEL: @_Z2p7bb
+; CHECK: icmp
+; CHECK: ret void
+
+; <label>:8 ; preds = %0
+ call void @_ZdaPv(i8* %4) #5
+ call void @_ZdaPv(i8* %5) #5
+ br label %9
+
+; <label>:9 ; preds = %0, %8
+ ret void
+}
+
+define void @_Z2p2v(i32 %c) #0 {
+ %mStackData = alloca [10 x i32], i32 %c, align 16
+ %1 = bitcast [10 x i32]* %mStackData to i8*
+ %2 = tail call noalias i8* @_Znam(i64 48) #4
+ %3 = bitcast i8* %2 to i32*
+ %4 = getelementptr inbounds [10 x i32]* %mStackData, i64 0, i64 0
+ %5 = icmp eq i32* %3, %4
+ br i1 %5, label %7, label %6
+
+; CHECK-LABEL: @_Z2p2v
+; CHECK: icmp
+; CHECK: ret void
+
+; <label>:6 ; preds = %0
+ call void @_ZdaPv(i8* %2) #5
+ br label %7
+
+; <label>:7 ; preds = %0, %6
+ ret void
+}
+
+; Function Attrs: nobuiltin
+declare noalias i8* @_Znam(i64) #2
+
+; Function Attrs: nobuiltin nounwind
+declare void @_ZdaPv(i8*) #3
+
+attributes #0 = { uwtable }
+attributes #1 = { nounwind }
+attributes #2 = { nobuiltin }
+attributes #3 = { nobuiltin nounwind }
+attributes #4 = { builtin }
+attributes #5 = { builtin nounwind }
+
diff --git a/test/Transforms/InstSimplify/select.ll b/test/Transforms/InstSimplify/select.ll
new file mode 100644
index 0000000..1d45e57
--- /dev/null
+++ b/test/Transforms/InstSimplify/select.ll
@@ -0,0 +1,161 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i32 @test1(i32 %x) {
+ %and = and i32 %x, 1
+ %cmp = icmp eq i32 %and, 0
+ %and1 = and i32 %x, -2
+ %and1.x = select i1 %cmp, i32 %and1, i32 %x
+ ret i32 %and1.x
+; CHECK-LABEL: @test1(
+; CHECK: ret i32 %x
+}
+
+define i32 @test2(i32 %x) {
+ %and = and i32 %x, 1
+ %cmp = icmp ne i32 %and, 0
+ %and1 = and i32 %x, -2
+ %and1.x = select i1 %cmp, i32 %x, i32 %and1
+ ret i32 %and1.x
+; CHECK-LABEL: @test2(
+; CHECK: ret i32 %x
+}
+
+define i32 @test3(i32 %x) {
+ %and = and i32 %x, 1
+ %cmp = icmp ne i32 %and, 0
+ %and1 = and i32 %x, -2
+ %and1.x = select i1 %cmp, i32 %and1, i32 %x
+ ret i32 %and1.x
+; CHECK-LABEL: @test3(
+; CHECK: %[[and:.*]] = and i32 %x, -2
+; CHECK: ret i32 %[[and]]
+}
+
+define i32 @test4(i32 %X) {
+ %cmp = icmp slt i32 %X, 0
+ %or = or i32 %X, -2147483648
+ %cond = select i1 %cmp, i32 %X, i32 %or
+ ret i32 %cond
+; CHECK-LABEL: @test4
+; CHECK: %[[or:.*]] = or i32 %X, -2147483648
+; CHECK: ret i32 %[[or]]
+}
+
+define i32 @test5(i32 %X) {
+ %cmp = icmp slt i32 %X, 0
+ %or = or i32 %X, -2147483648
+ %cond = select i1 %cmp, i32 %or, i32 %X
+ ret i32 %cond
+; CHECK-LABEL: @test5
+; CHECK: ret i32 %X
+}
+
+define i32 @test6(i32 %X) {
+ %cmp = icmp slt i32 %X, 0
+ %and = and i32 %X, 2147483647
+ %cond = select i1 %cmp, i32 %and, i32 %X
+ ret i32 %cond
+; CHECK-LABEL: @test6
+; CHECK: %[[and:.*]] = and i32 %X, 2147483647
+; CHECK: ret i32 %[[and]]
+}
+
+define i32 @test7(i32 %X) {
+ %cmp = icmp slt i32 %X, 0
+ %and = and i32 %X, 2147483647
+ %cond = select i1 %cmp, i32 %X, i32 %and
+ ret i32 %cond
+; CHECK-LABEL: @test7
+; CHECK: ret i32 %X
+}
+
+define i32 @test8(i32 %X) {
+ %cmp = icmp sgt i32 %X, -1
+ %or = or i32 %X, -2147483648
+ %cond = select i1 %cmp, i32 %X, i32 %or
+ ret i32 %cond
+; CHECK-LABEL: @test8
+; CHECK: ret i32 %X
+}
+
+define i32 @test9(i32 %X) {
+ %cmp = icmp sgt i32 %X, -1
+ %or = or i32 %X, -2147483648
+ %cond = select i1 %cmp, i32 %or, i32 %X
+ ret i32 %cond
+; CHECK-LABEL: @test9
+; CHECK: %[[or:.*]] = or i32 %X, -2147483648
+; CHECK: ret i32 %[[or]]
+}
+
+define i32 @test10(i32 %X) {
+ %cmp = icmp sgt i32 %X, -1
+ %and = and i32 %X, 2147483647
+ %cond = select i1 %cmp, i32 %and, i32 %X
+ ret i32 %cond
+; CHECK-LABEL: @test10
+; CHECK: ret i32 %X
+}
+
+define i32 @test11(i32 %X) {
+ %cmp = icmp sgt i32 %X, -1
+ %and = and i32 %X, 2147483647
+ %cond = select i1 %cmp, i32 %X, i32 %and
+ ret i32 %cond
+; CHECK-LABEL: @test11
+; CHECK: %[[and:.*]] = and i32 %X, 2147483647
+; CHECK: ret i32 %[[and]]
+}
+
+; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8(
+; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8
+; CHECK-NEXT: ret i32 [[OR]]
+define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) {
+ %and = and i32 %x, 8
+ %cmp = icmp eq i32 %and, 0
+ %or = or i32 %x, 8
+ %or.x = select i1 %cmp, i32 %or, i32 %x
+ ret i32 %or.x
+}
+
+; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8(
+; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9
+; CHECK-NEXT: ret i32 [[AND]]
+define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) {
+ %and = and i32 %x, 8
+ %cmp = icmp eq i32 %and, 0
+ %and1 = and i32 %x, -9
+ %x.and1 = select i1 %cmp, i32 %x, i32 %and1
+ ret i32 %x.and1
+}
+
+; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8(
+; CHECK-NEXT: ret i32 %x
+define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) {
+ %and = and i32 %x, 8
+ %cmp = icmp eq i32 %and, 0
+ %and1 = and i32 %x, -9
+ %and1.x = select i1 %cmp, i32 %and1, i32 %x
+ ret i32 %and1.x
+}
+
+; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8(
+; CHECK: select i1 %cmp, i64 %y, i64 %and1
+define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) {
+ %and = and i32 %x, 8
+ %cmp = icmp eq i32 %and, 0
+ %and1 = and i64 %y, -9
+ %y.and1 = select i1 %cmp, i64 %y, i64 %and1
+ ret i64 %y.and1
+}
+
+; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8(
+; CHECK: select i1 %cmp, i64 %and1, i64 %y
+define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) {
+ %and = and i32 %x, 8
+ %cmp = icmp eq i32 %and, 0
+ %and1 = and i64 %y, -9
+ %and1.y = select i1 %cmp, i64 %and1, i64 %y
+ ret i64 %and1.y
+}
+
diff --git a/test/Transforms/InstSimplify/undef.ll b/test/Transforms/InstSimplify/undef.ll
index 181c2ef..e8b49b6 100644
--- a/test/Transforms/InstSimplify/undef.ll
+++ b/test/Transforms/InstSimplify/undef.ll
@@ -160,3 +160,108 @@ define <4 x i8> @test19(<4 x i8> %a) {
%b = shl <4 x i8> %a, <i8 8, i8 9, i8 undef, i8 -1>
ret <4 x i8> %b
}
+
+; CHECK-LABEL: @test20
+; CHECK: ret i32 undef
+define i32 @test20(i32 %a) {
+ %b = udiv i32 %a, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test21
+; CHECK: ret i32 undef
+define i32 @test21(i32 %a) {
+ %b = sdiv i32 %a, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test22
+; CHECK: ret i32 undef
+define i32 @test22(i32 %a) {
+ %b = ashr exact i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test23
+; CHECK: ret i32 undef
+define i32 @test23(i32 %a) {
+ %b = lshr exact i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test24
+; CHECK: ret i32 undef
+define i32 @test24() {
+ %b = udiv i32 undef, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test25
+; CHECK: ret i32 undef
+define i32 @test25() {
+ %b = lshr i32 0, undef
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test26
+; CHECK: ret i32 undef
+define i32 @test26() {
+ %b = ashr i32 0, undef
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test27
+; CHECK: ret i32 undef
+define i32 @test27() {
+ %b = shl i32 0, undef
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test28
+; CHECK: ret i32 undef
+define i32 @test28(i32 %a) {
+ %b = shl nsw i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test29
+; CHECK: ret i32 undef
+define i32 @test29(i32 %a) {
+ %b = shl nuw i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test30
+; CHECK: ret i32 undef
+define i32 @test30(i32 %a) {
+ %b = shl nsw nuw i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test31
+; CHECK: ret i32 0
+define i32 @test31(i32 %a) {
+ %b = shl i32 undef, %a
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test32
+; CHECK: ret i32 undef
+define i32 @test32(i32 %a) {
+ %b = shl i32 undef, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test33
+; CHECK: ret i32 undef
+define i32 @test33(i32 %a) {
+ %b = ashr i32 undef, 0
+ ret i32 %b
+}
+
+; CHECK-LABEL: @test34
+; CHECK: ret i32 undef
+define i32 @test34(i32 %a) {
+ %b = lshr i32 undef, 0
+ ret i32 %b
+}