summaryrefslogtreecommitdiff
path: root/test/Transforms
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-08-20 21:02:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-08-20 21:02:43 +0000
commit15c5c77fa04cd97e1057e8a585f669fc49da0d92 (patch)
tree9047e00a30ccb7b81dbe7227c8c883cbafb5d2dd /test/Transforms
parent4e20bb0468b8d0db13287e666b482eb93689be99 (diff)
Notes
Diffstat (limited to 'test/Transforms')
-rw-r--r--test/Transforms/BDCE/invalidate-assumptions.ll100
-rw-r--r--test/Transforms/IndVarSimplify/exit_value_test2.ll28
-rw-r--r--test/Transforms/SimplifyCFG/pr34131.ll74
3 files changed, 199 insertions, 3 deletions
diff --git a/test/Transforms/BDCE/invalidate-assumptions.ll b/test/Transforms/BDCE/invalidate-assumptions.ll
new file mode 100644
index 000000000000..d165d74be86d
--- /dev/null
+++ b/test/Transforms/BDCE/invalidate-assumptions.ll
@@ -0,0 +1,100 @@
+; RUN: opt -bdce %s -S | FileCheck %s
+
+; The 'nuw' on the subtract allows us to deduce that %setbit is not demanded.
+; But if we change that value to '0', then the 'nuw' is no longer valid. If we don't
+; remove the 'nuw', another pass (-instcombine) may make a transform based on an
+; that incorrect assumption and we can miscompile:
+; https://bugs.llvm.org/show_bug.cgi?id=33695
+
+define i1 @PR33695(i1 %b, i8 %x) {
+; CHECK-LABEL: @PR33695(
+; CHECK-NEXT: [[SETBIT:%.*]] = or i8 %x, 64
+; CHECK-NEXT: [[LITTLE_NUMBER:%.*]] = zext i1 %b to i8
+; CHECK-NEXT: [[BIG_NUMBER:%.*]] = shl i8 0, 1
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[SUB]] to i1
+; CHECK-NEXT: ret i1 [[TRUNC]]
+;
+ %setbit = or i8 %x, 64
+ %little_number = zext i1 %b to i8
+ %big_number = shl i8 %setbit, 1
+ %sub = sub nuw i8 %big_number, %little_number
+ %trunc = trunc i8 %sub to i1
+ ret i1 %trunc
+}
+
+; Similar to above, but now with more no-wrap.
+; https://bugs.llvm.org/show_bug.cgi?id=34037
+
+define i64 @PR34037(i64 %m, i32 %r, i64 %j, i1 %b, i32 %k, i64 %p) {
+; CHECK-LABEL: @PR34037(
+; CHECK-NEXT: [[CONV:%.*]] = zext i32 %r to i64
+; CHECK-NEXT: [[AND:%.*]] = and i64 %m, 0
+; CHECK-NEXT: [[NEG:%.*]] = xor i64 0, 34359738367
+; CHECK-NEXT: [[OR:%.*]] = or i64 %j, 0
+; CHECK-NEXT: [[SHL:%.*]] = shl i64 0, 29
+; CHECK-NEXT: [[CONV1:%.*]] = select i1 %b, i64 7, i64 0
+; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[SHL]], [[CONV1]]
+; CHECK-NEXT: [[CONV2:%.*]] = zext i32 %k to i64
+; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[SUB]], [[CONV2]]
+; CHECK-NEXT: [[CONV4:%.*]] = and i64 %p, 65535
+; CHECK-NEXT: [[AND5:%.*]] = and i64 [[MUL]], [[CONV4]]
+; CHECK-NEXT: ret i64 [[AND5]]
+;
+ %conv = zext i32 %r to i64
+ %and = and i64 %m, %conv
+ %neg = xor i64 %and, 34359738367
+ %or = or i64 %j, %neg
+ %shl = shl i64 %or, 29
+ %conv1 = select i1 %b, i64 7, i64 0
+ %sub = sub nuw nsw i64 %shl, %conv1
+ %conv2 = zext i32 %k to i64
+ %mul = mul nsw i64 %sub, %conv2
+ %conv4 = and i64 %p, 65535
+ %and5 = and i64 %mul, %conv4
+ ret i64 %and5
+}
+
+; This is a manufactured example based on the 1st test to prove that the
+; assumption-killing algorithm stops at the call. Ie, it does not remove
+; nsw/nuw from the 'add' because a call demands all bits of its argument.
+
+declare i1 @foo(i1)
+
+define i1 @poison_on_call_user_is_ok(i1 %b, i8 %x) {
+; CHECK-LABEL: @poison_on_call_user_is_ok(
+; CHECK-NEXT: [[SETBIT:%.*]] = or i8 %x, 64
+; CHECK-NEXT: [[LITTLE_NUMBER:%.*]] = zext i1 %b to i8
+; CHECK-NEXT: [[BIG_NUMBER:%.*]] = shl i8 0, 1
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[SUB]] to i1
+; CHECK-NEXT: [[CALL_RESULT:%.*]] = call i1 @foo(i1 [[TRUNC]])
+; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i1 [[CALL_RESULT]], true
+; CHECK-NEXT: [[MUL:%.*]] = mul i1 [[TRUNC]], [[ADD]]
+; CHECK-NEXT: ret i1 [[MUL]]
+;
+ %setbit = or i8 %x, 64
+ %little_number = zext i1 %b to i8
+ %big_number = shl i8 %setbit, 1
+ %sub = sub nuw i8 %big_number, %little_number
+ %trunc = trunc i8 %sub to i1
+ %call_result = call i1 @foo(i1 %trunc)
+ %add = add nsw nuw i1 %call_result, 1
+ %mul = mul i1 %trunc, %add
+ ret i1 %mul
+}
+
+
+; We were asserting that all users of a trivialized integer-type instruction were
+; also integer-typed, but that's too strong. The alloca has a pointer-type result.
+
+define void @PR34179(i32* %a) {
+; CHECK-LABEL: @PR34179(
+; CHECK-NEXT: [[T0:%.*]] = load volatile i32, i32* %a
+; CHECK-NEXT: ret void
+;
+ %t0 = load volatile i32, i32* %a
+ %vla = alloca i32, i32 %t0
+ ret void
+}
+
diff --git a/test/Transforms/IndVarSimplify/exit_value_test2.ll b/test/Transforms/IndVarSimplify/exit_value_test2.ll
index ee641667506c..7b6e91a742b2 100644
--- a/test/Transforms/IndVarSimplify/exit_value_test2.ll
+++ b/test/Transforms/IndVarSimplify/exit_value_test2.ll
@@ -3,15 +3,14 @@
; Check IndVarSimplify should not replace exit value because or else
; udiv will be introduced by expand and the cost will be high.
-;
-; CHECK-LABEL: @_Z3fooPKcjj(
-; CHECK-NOT: udiv
declare void @_Z3mixRjj(i32* dereferenceable(4), i32)
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
define i32 @_Z3fooPKcjj(i8* nocapture readonly %s, i32 %len, i32 %c) {
+; CHECK-LABEL: @_Z3fooPKcjj(
+; CHECK-NOT: udiv
entry:
%a = alloca i32, align 4
%tmp = bitcast i32* %a to i8*
@@ -50,3 +49,26 @@ while.end: ; preds = %while.cond.while.en
call void @llvm.lifetime.end.p0i8(i64 4, i8* %tmp)
ret i32 %tmp4
}
+
+define i32 @zero_backedge_count_test(i32 %unknown_init, i32* %unknown_mem) {
+; CHECK-LABEL: @zero_backedge_count_test(
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [ 0, %entry], [ %iv.inc, %loop ]
+ %unknown_phi = phi i32 [ %unknown_init, %entry ], [ %unknown_next, %loop ]
+ %iv.inc = add i32 %iv, 1
+ %be_taken = icmp ne i32 %iv.inc, 1
+ %unknown_next = load volatile i32, i32* %unknown_mem
+ br i1 %be_taken, label %loop, label %leave
+
+leave:
+; We can fold %unknown_phi even though the backedge value for it is completely
+; unknown, since we can prove that the loop's backedge taken count is 0.
+
+; CHECK: leave:
+; CHECK: ret i32 %unknown_init
+ %exit_val = phi i32 [ %unknown_phi, %loop ]
+ ret i32 %exit_val
+}
diff --git a/test/Transforms/SimplifyCFG/pr34131.ll b/test/Transforms/SimplifyCFG/pr34131.ll
new file mode 100644
index 000000000000..b64b6876e04e
--- /dev/null
+++ b/test/Transforms/SimplifyCFG/pr34131.ll
@@ -0,0 +1,74 @@
+; RUN: opt -simplifycfg -S < %s | FileCheck %s
+
+; Just checking for lack of crash here, but we should be able to check the IR?
+; Earlier version using auto-generated checks from utils/update_test_checks.py
+; had bot problems though...
+
+define void @patatino() {
+
+; CHECK-LABEL: @patatino
+
+ br label %bb1
+bb1: ; preds = %bb36, %0
+ br label %bb2
+bb2: ; preds = %bb3, %bb1
+ br i1 undef, label %bb4, label %bb3
+bb3: ; preds = %bb4, %bb2
+ br i1 undef, label %bb2, label %bb5
+bb4: ; preds = %bb2
+ switch i32 undef, label %bb3 [
+ ]
+bb5: ; preds = %bb3
+ br label %bb6
+bb6: ; preds = %bb5
+ br i1 undef, label %bb7, label %bb9
+bb7: ; preds = %bb6
+ %tmp = or i64 undef, 1
+ %tmp8 = icmp ult i64 %tmp, 0
+ br i1 %tmp8, label %bb12, label %bb9
+bb9: ; preds = %bb35, %bb34, %bb33, %bb32, %bb31, %bb30, %bb27, %bb24, %bb21, %bb18, %bb16, %bb14, %bb12, %bb7, %bb6
+ br label %bb11
+bb10: ; preds = %bb36
+ br label %bb11
+bb11: ; preds = %bb10, %bb9
+ ret void
+bb12: ; preds = %bb7
+ %tmp13 = icmp ult i64 0, 0
+ br i1 %tmp13, label %bb14, label %bb9
+bb14: ; preds = %bb12
+ %tmp15 = icmp ult i64 undef, 0
+ br i1 %tmp15, label %bb16, label %bb9
+bb16: ; preds = %bb14
+ %tmp17 = icmp ult i64 undef, 0
+ br i1 %tmp17, label %bb18, label %bb9
+bb18: ; preds = %bb16
+ %tmp19 = or i64 undef, 5
+ %tmp20 = icmp ult i64 %tmp19, 0
+ br i1 %tmp20, label %bb21, label %bb9
+bb21: ; preds = %bb18
+ %tmp22 = or i64 undef, 6
+ %tmp23 = icmp ult i64 %tmp22, 0
+ br i1 %tmp23, label %bb24, label %bb9
+bb24: ; preds = %bb21
+ %tmp25 = or i64 undef, 7
+ %tmp26 = icmp ult i64 %tmp25, 0
+ br i1 %tmp26, label %bb27, label %bb9
+bb27: ; preds = %bb24
+ %tmp28 = or i64 undef, 8
+ %tmp29 = icmp ult i64 %tmp28, 0
+ br i1 %tmp29, label %bb30, label %bb9
+bb30: ; preds = %bb27
+ br i1 undef, label %bb31, label %bb9
+bb31: ; preds = %bb30
+ br i1 undef, label %bb32, label %bb9
+bb32: ; preds = %bb31
+ br i1 undef, label %bb33, label %bb9
+bb33: ; preds = %bb32
+ br i1 undef, label %bb34, label %bb9
+bb34: ; preds = %bb33
+ br i1 undef, label %bb35, label %bb9
+bb35: ; preds = %bb34
+ br i1 undef, label %bb36, label %bb9
+bb36: ; preds = %bb35
+ br i1 undef, label %bb1, label %bb10
+}