• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -bdce %s -S | FileCheck %s
3
4; The 'nuw' on the subtract allows us to deduce that %setbit is not demanded.
5; But if we change that value to '0', then the 'nuw' is no longer valid. If we don't
6; remove the 'nuw', another pass (-instcombine) may make a transform based on an
7; that incorrect assumption and we can miscompile:
8; https://bugs.llvm.org/show_bug.cgi?id=33695
9
10define i1 @PR33695(i1 %b, i8 %x) {
11; CHECK-LABEL: @PR33695(
12; CHECK-NEXT:    [[LITTLE_NUMBER:%.*]] = zext i1 [[B:%.*]] to i8
13; CHECK-NEXT:    [[BIG_NUMBER:%.*]] = shl i8 0, 1
14; CHECK-NEXT:    [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]]
15; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i8 [[SUB]] to i1
16; CHECK-NEXT:    ret i1 [[TRUNC]]
17;
18  %setbit = or i8 %x, 64
19  %little_number = zext i1 %b to i8
20  %big_number = shl i8 %setbit, 1
21  %sub = sub nuw i8 %big_number, %little_number
22  %trunc = trunc i8 %sub to i1
23  ret i1 %trunc
24}
25
26; Similar to above, but now with more no-wrap.
27; https://bugs.llvm.org/show_bug.cgi?id=34037
28
29define i64 @PR34037(i64 %m, i32 %r, i64 %j, i1 %b, i32 %k, i64 %p) {
30; CHECK-LABEL: @PR34037(
31; CHECK-NEXT:    [[SHL:%.*]] = shl i64 0, 29
32; CHECK-NEXT:    [[CONV1:%.*]] = select i1 [[B:%.*]], i64 7, i64 0
33; CHECK-NEXT:    [[SUB:%.*]] = sub i64 [[SHL]], [[CONV1]]
34; CHECK-NEXT:    [[CONV2:%.*]] = zext i32 [[K:%.*]] to i64
35; CHECK-NEXT:    [[MUL:%.*]] = mul i64 [[SUB]], [[CONV2]]
36; CHECK-NEXT:    [[CONV4:%.*]] = and i64 [[P:%.*]], 65535
37; CHECK-NEXT:    [[AND5:%.*]] = and i64 [[MUL]], [[CONV4]]
38; CHECK-NEXT:    ret i64 [[AND5]]
39;
40  %conv = zext i32 %r to i64
41  %and = and i64 %m, %conv
42  %neg = xor i64 %and, 34359738367
43  %or = or i64 %j, %neg
44  %shl = shl i64 %or, 29
45  %conv1 = select i1 %b, i64 7, i64 0
46  %sub = sub nuw nsw i64 %shl, %conv1
47  %conv2 = zext i32 %k to i64
48  %mul = mul nsw i64 %sub, %conv2
49  %conv4 = and i64 %p, 65535
50  %and5 = and i64 %mul, %conv4
51  ret i64 %and5
52}
53
54; This is a manufactured example based on the 1st test to prove that the
55; assumption-killing algorithm stops at the call. Ie, it does not remove
56; nsw/nuw from the 'add' because a call demands all bits of its argument.
57
58declare i1 @foo(i1)
59
60define i1 @poison_on_call_user_is_ok(i1 %b, i8 %x) {
61; CHECK-LABEL: @poison_on_call_user_is_ok(
62; CHECK-NEXT:    [[LITTLE_NUMBER:%.*]] = zext i1 [[B:%.*]] to i8
63; CHECK-NEXT:    [[BIG_NUMBER:%.*]] = shl i8 0, 1
64; CHECK-NEXT:    [[SUB:%.*]] = sub i8 [[BIG_NUMBER]], [[LITTLE_NUMBER]]
65; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i8 [[SUB]] to i1
66; CHECK-NEXT:    [[CALL_RESULT:%.*]] = call i1 @foo(i1 [[TRUNC]])
67; CHECK-NEXT:    [[ADD:%.*]] = add nuw nsw i1 [[CALL_RESULT]], true
68; CHECK-NEXT:    [[MUL:%.*]] = mul i1 [[TRUNC]], [[ADD]]
69; CHECK-NEXT:    ret i1 [[MUL]]
70;
71  %setbit = or i8 %x, 64
72  %little_number = zext i1 %b to i8
73  %big_number = shl i8 %setbit, 1
74  %sub = sub nuw i8 %big_number, %little_number
75  %trunc = trunc i8 %sub to i1
76  %call_result = call i1 @foo(i1 %trunc)
77  %add = add nsw nuw i1 %call_result, 1
78  %mul = mul i1 %trunc, %add
79  ret i1 %mul
80}
81
82
83; We were asserting that all users of a trivialized integer-type instruction were
84; also integer-typed, but that's too strong. The alloca has a pointer-type result.
85
86define void @PR34179(i32* %a) {
87; CHECK-LABEL: @PR34179(
88; CHECK-NEXT:    [[T0:%.*]] = load volatile i32, i32* [[A:%.*]]
89; CHECK-NEXT:    ret void
90;
91  %t0 = load volatile i32, i32* %a
92  %vla = alloca i32, i32 %t0
93  ret void
94}
95
96