aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/ValueTracking
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:46:15 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:46:15 +0000
commitdd58ef019b700900793a1eb48b52123db01b654e (patch)
treefcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /test/Analysis/ValueTracking
parent2fe5752e3a7c345cdb59e869278d36af33c13fa4 (diff)
Notes
Diffstat (limited to 'test/Analysis/ValueTracking')
-rw-r--r--test/Analysis/ValueTracking/known-bits-from-range-md.ll34
-rw-r--r--test/Analysis/ValueTracking/known-non-equal.ll21
-rw-r--r--test/Analysis/ValueTracking/knownnonzero-shift.ll13
-rw-r--r--test/Analysis/ValueTracking/knownzero-shift.ll14
-rw-r--r--test/Analysis/ValueTracking/memory-dereferenceable.ll117
-rw-r--r--test/Analysis/ValueTracking/monotonic-phi.ll49
-rw-r--r--test/Analysis/ValueTracking/pr24866.ll44
7 files changed, 275 insertions, 17 deletions
diff --git a/test/Analysis/ValueTracking/known-bits-from-range-md.ll b/test/Analysis/ValueTracking/known-bits-from-range-md.ll
new file mode 100644
index 000000000000..e1de089b3501
--- /dev/null
+++ b/test/Analysis/ValueTracking/known-bits-from-range-md.ll
@@ -0,0 +1,34 @@
+; RUN: opt -S -instsimplify < %s | FileCheck %s
+
+define i1 @test0(i8* %ptr) {
+; CHECK-LABEL: @test0(
+ entry:
+ %val = load i8, i8* %ptr, !range !{i8 -50, i8 0}
+ %and = and i8 %val, 128
+ %is.eq = icmp eq i8 %and, 128
+ ret i1 %is.eq
+; CHECK: ret i1 true
+}
+
+define i1 @test1(i8* %ptr) {
+; CHECK-LABEL: @test1(
+ entry:
+ %val = load i8, i8* %ptr, !range !{i8 64, i8 128}
+ %and = and i8 %val, 64
+ %is.eq = icmp eq i8 %and, 64
+ ret i1 %is.eq
+; CHECK: ret i1 true
+}
+
+define i1 @test2(i8* %ptr) {
+; CHECK-LABEL: @test2(
+ entry:
+; CHECK: load
+; CHECK: and
+; CHECK: icmp eq
+; CHECK: ret
+ %val = load i8, i8* %ptr, !range !{i8 64, i8 129}
+ %and = and i8 %val, 64
+ %is.eq = icmp eq i8 %and, 64
+ ret i1 %is.eq
+}
diff --git a/test/Analysis/ValueTracking/known-non-equal.ll b/test/Analysis/ValueTracking/known-non-equal.ll
new file mode 100644
index 000000000000..d28b3f4f63a3
--- /dev/null
+++ b/test/Analysis/ValueTracking/known-non-equal.ll
@@ -0,0 +1,21 @@
+; RUN: opt -instsimplify < %s -S | FileCheck %s
+
+; CHECK: define i1 @test
+define i1 @test(i8* %pq, i8 %B) {
+ %q = load i8, i8* %pq, !range !0 ; %q is known nonzero; no known bits
+ %A = add nsw i8 %B, %q
+ %cmp = icmp eq i8 %A, %B
+ ; CHECK: ret i1 false
+ ret i1 %cmp
+}
+
+; CHECK: define i1 @test2
+define i1 @test2(i8 %a, i8 %b) {
+ %A = or i8 %a, 2 ; %A[1] = 1
+ %B = and i8 %b, -3 ; %B[1] = 0
+ %cmp = icmp eq i8 %A, %B ; %A[1] and %B[1] are contradictory.
+ ; CHECK: ret i1 false
+ ret i1 %cmp
+}
+
+!0 = !{ i8 1, i8 5 }
diff --git a/test/Analysis/ValueTracking/knownnonzero-shift.ll b/test/Analysis/ValueTracking/knownnonzero-shift.ll
new file mode 100644
index 000000000000..e59d19cc2e26
--- /dev/null
+++ b/test/Analysis/ValueTracking/knownnonzero-shift.ll
@@ -0,0 +1,13 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+; CHECK-LABEL: @test
+define i1 @test(i8 %p, i8* %pq) {
+ %q = load i8, i8* %pq, !range !0 ; %q is known nonzero; no known bits
+ %1 = shl i8 %p, %q ; because %q is nonzero, %1[0] is known to be zero.
+ %2 = and i8 %1, 1
+ %x = icmp eq i8 %2, 0
+ ; CHECK: ret i1 true
+ ret i1 %x
+}
+
+!0 = !{ i8 1, i8 5 }
diff --git a/test/Analysis/ValueTracking/knownzero-shift.ll b/test/Analysis/ValueTracking/knownzero-shift.ll
new file mode 100644
index 000000000000..835d87a9d9c1
--- /dev/null
+++ b/test/Analysis/ValueTracking/knownzero-shift.ll
@@ -0,0 +1,14 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+; CHECK-LABEL: @test
+define i1 @test(i8 %p, i8* %pq) {
+ %q = load i8, i8* %pq, !range !0 ; %q is known nonzero; no known bits
+ %1 = or i8 %p, 2 ; %1[1] = 1
+ %2 = and i8 %1, 254 ; %2[0] = 0, %2[1] = 1
+ %A = lshr i8 %2, 1 ; We should know that %A is nonzero.
+ %x = icmp eq i8 %A, 0
+ ; CHECK: ret i1 false
+ ret i1 %x
+}
+
+!0 = !{ i8 1, i8 5 }
diff --git a/test/Analysis/ValueTracking/memory-dereferenceable.ll b/test/Analysis/ValueTracking/memory-dereferenceable.ll
index f49f4f77f404..5b45172f695e 100644
--- a/test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ b/test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -5,73 +5,156 @@
target datalayout = "e"
+%TypeOpaque = type opaque
+
declare zeroext i1 @return_i1()
+declare i32* @foo()
@globalstr = global [6 x i8] c"hello\00"
@globali32ptr = external global i32*
%struct.A = type { [8 x i8], [5 x i8] }
@globalstruct = external global %struct.A
-define void @test(i32 addrspace(1)* dereferenceable(8) %dparam) gc "statepoint-example" {
+@globalptr.align1 = external global i8, align 1
+@globalptr.align16 = external global i8, align 16
+
+; CHECK-LABEL: 'test'
+define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
+ i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1,
+ i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16)
+ gc "statepoint-example" {
; CHECK: The following are dereferenceable:
-; CHECK: %globalptr
-; CHECK: %alloca
-; CHECK: %dparam
-; CHECK: %relocate
-; CHECK-NOT: %nparam
-; CHECK-NOT: %nd_load
-; CHECK: %d4_load
-; CHECK-NOT: %d2_load
-; CHECK-NOT: %d_or_null_load
-; CHECK: %d_or_null_non_null_load
-; CHECK: %within_allocation
-; CHECK-NOT: %outside_allocation
entry:
+; CHECK: %globalptr{{.*}}(aligned)
%globalptr = getelementptr inbounds [6 x i8], [6 x i8]* @globalstr, i32 0, i32 0
%load1 = load i8, i8* %globalptr
+
+; CHECK: %alloca{{.*}}(aligned)
%alloca = alloca i1
%load2 = load i1, i1* %alloca
+
+; CHECK: %dparam{{.*}}(aligned)
%load3 = load i32, i32 addrspace(1)* %dparam
- %tok = tail call i32 (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam)
- %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7)
+
+; CHECK: %relocate{{.*}}(aligned)
+ %tok = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam)
+ %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok, i32 7, i32 7)
%load4 = load i32, i32 addrspace(1)* %relocate
+
+; CHECK-NOT: %nparam
%nparam = getelementptr i32, i32 addrspace(1)* %dparam, i32 5
%load5 = load i32, i32 addrspace(1)* %nparam
; Load from a non-dereferenceable load
+; CHECK-NOT: %nd_load
%nd_load = load i32*, i32** @globali32ptr
%load6 = load i32, i32* %nd_load
; Load from a dereferenceable load
+; CHECK: %d4_load{{.*}}(aligned)
%d4_load = load i32*, i32** @globali32ptr, !dereferenceable !0
%load7 = load i32, i32* %d4_load
; Load from an offset not covered by the dereferenceable portion
+; CHECK-NOT: %d2_load
%d2_load = load i32*, i32** @globali32ptr, !dereferenceable !1
%load8 = load i32, i32* %d2_load
; Load from a potentially null pointer with dereferenceable_or_null
+; CHECK-NOT: %d_or_null_load
%d_or_null_load = load i32*, i32** @globali32ptr, !dereferenceable_or_null !0
%load9 = load i32, i32* %d_or_null_load
; Load from a non-null pointer with dereferenceable_or_null
+; CHECK: %d_or_null_non_null_load{{.*}}(aligned)
%d_or_null_non_null_load = load i32*, i32** @globali32ptr, !nonnull !2, !dereferenceable_or_null !0
%load10 = load i32, i32* %d_or_null_non_null_load
; It's OK to overrun static array size as long as we stay within underlying object size
+; CHECK: %within_allocation{{.*}}(aligned)
%within_allocation = getelementptr inbounds %struct.A, %struct.A* @globalstruct, i64 0, i32 0, i64 10
%load11 = load i8, i8* %within_allocation
; GEP is outside the underlying object size
+; CHECK-NOT: %outside_allocation
%outside_allocation = getelementptr inbounds %struct.A, %struct.A* @globalstruct, i64 0, i32 1, i64 10
%load12 = load i8, i8* %outside_allocation
+ ; Loads from aligned globals
+; CHECK: @globalptr.align1{{.*}}(unaligned)
+; CHECK: @globalptr.align16{{.*}}(aligned)
+ %load13 = load i8, i8* @globalptr.align1, align 16
+ %load14 = load i8, i8* @globalptr.align16, align 16
+
+ ; Loads from aligned arguments
+; CHECK: %dparam.align1{{.*}}(unaligned)
+; CHECK: %dparam.align16{{.*}}(aligned)
+ %load15 = load i8, i8 addrspace(1)* %dparam.align1, align 16
+ %load16 = load i8, i8 addrspace(1)* %dparam.align16, align 16
+
+ ; Loads from aligned allocas
+; CHECK: %alloca.align1{{.*}}(unaligned)
+; CHECK: %alloca.align16{{.*}}(aligned)
+ %alloca.align1 = alloca i1, align 1
+ %alloca.align16 = alloca i1, align 16
+ %load17 = load i1, i1* %alloca.align1, align 16
+ %load18 = load i1, i1* %alloca.align16, align 16
+
+ ; Loads from GEPs
+; CHECK: %gep.align1.offset1{{.*}}(unaligned)
+; CHECK: %gep.align16.offset1{{.*}}(unaligned)
+; CHECK: %gep.align1.offset16{{.*}}(unaligned)
+; CHECK: %gep.align16.offset16{{.*}}(aligned)
+ %gep.align1.offset1 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align1, i32 1
+ %gep.align16.offset1 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align16, i32 1
+ %gep.align1.offset16 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align1, i32 16
+ %gep.align16.offset16 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align16, i32 16
+ %load19 = load i8, i8 addrspace(1)* %gep.align1.offset1, align 16
+ %load20 = load i8, i8 addrspace(1)* %gep.align16.offset1, align 16
+ %load21 = load i8, i8 addrspace(1)* %gep.align1.offset16, align 16
+ %load22 = load i8, i8 addrspace(1)* %gep.align16.offset16, align 16
+
+; CHECK-NOT: %no_deref_return
+; CHECK: %deref_return{{.*}}(unaligned)
+; CHECK: %deref_and_aligned_return{{.*}}(aligned)
+ %no_deref_return = call i32* @foo()
+ %deref_return = call dereferenceable(32) i32* @foo()
+ %deref_and_aligned_return = call dereferenceable(32) align 16 i32* @foo()
+ %load23 = load i32, i32* %no_deref_return
+ %load24 = load i32, i32* %deref_return, align 16
+ %load25 = load i32, i32* %deref_and_aligned_return, align 16
+
+ ; Load from a dereferenceable and aligned load
+; CHECK: %d4_unaligned_load{{.*}}(unaligned)
+; CHECK: %d4_aligned_load{{.*}}(aligned)
+ %d4_unaligned_load = load i32*, i32** @globali32ptr, !dereferenceable !0
+ %d4_aligned_load = load i32*, i32** @globali32ptr, !dereferenceable !0, !align !{i64 16}
+ %load26 = load i32, i32* %d4_unaligned_load, align 16
+ %load27 = load i32, i32* %d4_aligned_load, align 16
+
ret void
}
-declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
-declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)
+; Just check that we don't crash.
+; CHECK-LABEL: 'opaque_type_crasher'
+define void @opaque_type_crasher(%TypeOpaque* dereferenceable(16) %a) {
+entry:
+ %bc = bitcast %TypeOpaque* %a to i8*
+ %ptr8 = getelementptr inbounds i8, i8* %bc, i32 8
+ %ptr32 = bitcast i8* %ptr8 to i32*
+ br i1 undef, label %if.then, label %if.end
+
+if.then:
+ %res = load i32, i32* %ptr32, align 4
+ br label %if.end
+
+if.end:
+ ret void
+}
+
+declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
+declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)
!0 = !{i64 4}
!1 = !{i64 2}
diff --git a/test/Analysis/ValueTracking/monotonic-phi.ll b/test/Analysis/ValueTracking/monotonic-phi.ll
new file mode 100644
index 000000000000..3204bda49f0b
--- /dev/null
+++ b/test/Analysis/ValueTracking/monotonic-phi.ll
@@ -0,0 +1,49 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+; CHECK-LABEL: @test1
+define i1 @test1(i8 %p, i8* %pq, i8 %n, i8 %r) {
+entry:
+ br label %loop
+loop:
+ %A = phi i8 [ 1, %entry ], [ %next, %loop ]
+ %next = add nsw i8 %A, 1
+ %cmp1 = icmp eq i8 %A, %n
+ br i1 %cmp1, label %exit, label %loop
+exit:
+ %add = or i8 %A, %r
+ %cmp = icmp eq i8 %add, 0
+ ; CHECK: ret i1 false
+ ret i1 %cmp
+}
+
+; CHECK-LABEL: @test2
+define i1 @test2(i8 %p, i8* %pq, i8 %n, i8 %r) {
+entry:
+ br label %loop
+loop:
+ %A = phi i8 [ 1, %entry ], [ %next, %loop ]
+ %next = add i8 %A, 1
+ %cmp1 = icmp eq i8 %A, %n
+ br i1 %cmp1, label %exit, label %loop
+exit:
+ %add = or i8 %A, %r
+ %cmp = icmp eq i8 %add, 0
+ ; CHECK-NOT: ret i1 false
+ ret i1 %cmp
+}
+
+; CHECK-LABEL: @test3
+define i1 @test3(i8 %p, i8* %pq, i8 %n, i8 %r) {
+entry:
+ br label %loop
+loop:
+ %A = phi i8 [ 1, %entry ], [ %next, %loop ]
+ %next = add nuw i8 %A, 1
+ %cmp1 = icmp eq i8 %A, %n
+ br i1 %cmp1, label %exit, label %loop
+exit:
+ %add = or i8 %A, %r
+ %cmp = icmp eq i8 %add, 0
+ ; CHECK: ret i1 false
+ ret i1 %cmp
+}
diff --git a/test/Analysis/ValueTracking/pr24866.ll b/test/Analysis/ValueTracking/pr24866.ll
new file mode 100644
index 000000000000..b146b4ac0564
--- /dev/null
+++ b/test/Analysis/ValueTracking/pr24866.ll
@@ -0,0 +1,44 @@
+; RUN: opt -S %s -value-tracking-dom-conditions -licm -load-combine | FileCheck %s
+; In pr24866.ll, we saw a crash when accessing a nullptr returned when
+; asking for a dominator tree Node. This reproducer is really fragile,
+; but it's currently the best we have.
+
+%struct.c_derived_tbl.2.5.8.11.14.17.23.38.59.80.92.98.104.107.155.183 = type { [256 x i32], [256 x i8] }
+
+
+; Function Attrs: nounwind uwtable
+define void @encode_one_blockX2(%struct.c_derived_tbl.2.5.8.11.14.17.23.38.59.80.92.98.104.107.155.183* nocapture readonly %actbl) #0 {
+; CHECK-LABEL: @encode_one_blockX2
+entry:
+ br i1 false, label %L_KLOOP_01, label %L_KLOOP.preheader
+
+L_KLOOP_01: ; preds = %while.end, %entry
+ br label %L_KLOOP.preheader
+
+L_KLOOP_08: ; preds = %while.end
+ br label %L_KLOOP.preheader
+
+L_KLOOP.preheader: ; preds = %L_KLOOP_08, %L_KLOOP_01, %entry
+ %r.2.ph = phi i32 [ undef, %L_KLOOP_08 ], [ 0, %entry ], [ undef, %L_KLOOP_01 ]
+ br label %L_KLOOP
+
+L_KLOOP: ; preds = %while.end, %L_KLOOP.preheader
+ %r.2 = phi i32 [ 0, %while.end ], [ %r.2.ph, %L_KLOOP.preheader ]
+ br i1 true, label %while.body, label %while.end
+
+while.body: ; preds = %while.body, %L_KLOOP
+ br label %while.body
+
+while.end: ; preds = %L_KLOOP
+ %shl105 = shl i32 %r.2, 4
+ %add106 = add nsw i32 %shl105, undef
+ %idxprom107 = sext i32 %add106 to i64
+ %arrayidx108 = getelementptr inbounds %struct.c_derived_tbl.2.5.8.11.14.17.23.38.59.80.92.98.104.107.155.183, %struct.c_derived_tbl.2.5.8.11.14.17.23.38.59.80.92.98.104.107.155.183* %actbl, i64 0, i32 0, i64 %idxprom107
+ %0 = load i32, i32* %arrayidx108, align 4
+ %arrayidx110 = getelementptr inbounds %struct.c_derived_tbl.2.5.8.11.14.17.23.38.59.80.92.98.104.107.155.183, %struct.c_derived_tbl.2.5.8.11.14.17.23.38.59.80.92.98.104.107.155.183* %actbl, i64 0, i32 1, i64 %idxprom107
+ %1 = load i8, i8* %arrayidx110, align 1
+ indirectbr i8* undef, [label %L_KLOOP_DONE, label %L_KLOOP_01, label %L_KLOOP_08, label %L_KLOOP]
+
+L_KLOOP_DONE: ; preds = %while.end
+ ret void
+}