1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 target datalayout = "n32"
6 define i32 @sterix(i32, i8, i64) {
7 ; CHECK-LABEL: @sterix(
9 ; CHECK-NEXT: [[CONV:%.*]] = zext i32 [[TMP0:%.*]] to i64
10 ; CHECK-NEXT: [[CONV1:%.*]] = sext i8 [[TMP1:%.*]] to i32
11 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[CONV1]], 1945964878
12 ; CHECK-NEXT: [[SH_PROM:%.*]] = trunc i64 [[TMP2:%.*]] to i32
13 ; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[MUL]], [[SH_PROM]]
14 ; CHECK-NEXT: [[CONV2:%.*]] = zext i32 [[SHR]] to i64
15 ; CHECK-NEXT: [[MUL3:%.*]] = mul nuw nsw i64 [[CONV]], [[CONV2]]
16 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp samesign ult i64 [[MUL3]], 4294967296
17 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[LOR_RHS:%.*]], label [[LOR_END:%.*]]
19 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[TMP2]], [[MUL3]]
20 ; CHECK-NEXT: [[TOBOOL7_NOT:%.*]] = icmp eq i64 [[AND]], 0
21 ; CHECK-NEXT: [[TMP3:%.*]] = zext i1 [[TOBOOL7_NOT]] to i32
22 ; CHECK-NEXT: br label [[LOR_END]]
24 ; CHECK-NEXT: [[CONV8:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[TMP3]], [[LOR_RHS]] ]
25 ; CHECK-NEXT: ret i32 [[CONV8]]
28 %conv = zext i32 %0 to i64
29 %conv1 = sext i8 %1 to i32
30 %mul = mul i32 %conv1, 1945964878
31 %sh_prom = trunc i64 %2 to i32
32 %shr = lshr i32 %mul, %sh_prom
33 %conv2 = zext i32 %shr to i64
34 %mul3 = mul nuw nsw i64 %conv, %conv2
35 %conv6 = and i64 %mul3, 4294967295
36 %tobool = icmp ne i64 %conv6, %mul3
37 br i1 %tobool, label %lor.end, label %lor.rhs
40 %and = and i64 %2, %mul3
41 %conv4 = trunc i64 %and to i32
42 %tobool7 = icmp ne i32 %conv4, 0
43 %lnot = xor i1 %tobool7, true
47 %3 = phi i1 [ true, %entry ], [ %lnot, %lor.rhs ]
48 %conv8 = zext i1 %3 to i32
52 ; https://bugs.llvm.org/show_bug.cgi?id=33765
54 @glob = external global i16
56 define void @PR33765(i8 %beth) {
57 ; CHECK-LABEL: @PR33765(
58 ; CHECK-NEXT: br i1 false, label [[IF_THEN9:%.*]], label [[IF_THEN9]]
60 ; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[BETH:%.*]] to i32
61 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[CONV]], [[CONV]]
62 ; CHECK-NEXT: [[TINKY:%.*]] = load i16, ptr @glob, align 2
63 ; CHECK-NEXT: [[TMP1:%.*]] = trunc nuw i32 [[MUL]] to i16
64 ; CHECK-NEXT: [[CONV14:%.*]] = and i16 [[TINKY]], [[TMP1]]
65 ; CHECK-NEXT: store i16 [[CONV14]], ptr @glob, align 2
66 ; CHECK-NEXT: ret void
68 %conv = zext i8 %beth to i32
69 %mul = mul nuw nsw i32 %conv, %conv
70 %conv3 = and i32 %mul, 255
71 %tobool8 = icmp ne i32 %mul, %conv3
72 br i1 %tobool8, label %if.then9, label %if.then9
75 %tinky = load i16, ptr @glob
76 %conv13 = sext i16 %tinky to i32
77 %and = and i32 %mul, %conv13
78 %conv14 = trunc i32 %and to i16
79 store i16 %conv14, ptr @glob
83 ; Repro case for bug involving mutating a list while
88 define i16 @iter_breaker(i16 %a, i16 %b) {
89 ; CHECK-LABEL: @iter_breaker(
90 ; CHECK-NEXT: [[UMUL:%.*]] = call { i16, i1 } @llvm.umul.with.overflow.i16(i16 [[A:%.*]], i16 [[B:%.*]])
91 ; CHECK-NEXT: [[UMUL_VALUE:%.*]] = extractvalue { i16, i1 } [[UMUL]], 0
92 ; CHECK-NEXT: [[DID_OVF:%.*]] = extractvalue { i16, i1 } [[UMUL]], 1
93 ; CHECK-NEXT: br i1 [[DID_OVF]], label [[RET1:%.*]], label [[RET2:%.*]]
95 ; CHECK-NEXT: [[TRUNC_REMAIN:%.*]] = trunc i16 [[UMUL_VALUE]] to i8
96 ; CHECK-NEXT: [[VAL:%.*]] = call i16 @aux(i8 [[TRUNC_REMAIN]])
97 ; CHECK-NEXT: ret i16 [[VAL]]
99 ; CHECK-NEXT: ret i16 [[UMUL_VALUE]]
101 %a_wide = zext i16 %a to i32
102 %b_wide = zext i16 %b to i32
103 %mul_wide = mul i32 %a_wide, %b_wide ; uses of %mul_wide will be iterated
105 %trunc_remain = trunc i32 %mul_wide to i8 ; this use will be replaced w/ new value
106 ; when iteration visits it, switching
107 ; iteration to the uses of new value
109 %trunc_unnecessary = trunc i32 %mul_wide to i16 ; uses of %trunc_unnecessary will have
110 ; been updated to uses of new value
112 %did_ovf = icmp ugt i32 %mul_wide, 65535
113 br i1 %did_ovf, label %ret1, label %ret2
116 %val = call i16 @aux(i8 %trunc_remain)
120 ret i16 %trunc_unnecessary ; crash visiting this use after corrupting iterator
123 ; This miscompiled because of broken pattern matching.
125 define i1 @PR46561(i1 %a, i1 %x, i1 %y, i8 %z) {
126 ; CHECK-LABEL: @PR46561(
128 ; CHECK-NEXT: br i1 [[A:%.*]], label [[COND_TRUE:%.*]], label [[END:%.*]]
130 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
131 ; CHECK-NEXT: [[TMP0:%.*]] = trunc i8 [[Z:%.*]] to i1
132 ; CHECK-NEXT: [[TMP1:%.*]] = xor i1 [[MULBOOL]], [[TMP0]]
133 ; CHECK-NEXT: [[TMP2:%.*]] = xor i1 [[TMP1]], true
134 ; CHECK-NEXT: br label [[END]]
136 ; CHECK-NEXT: [[P:%.*]] = phi i1 [ [[TMP2]], [[COND_TRUE]] ], [ false, [[ENTRY:%.*]] ]
137 ; CHECK-NEXT: ret i1 [[P]]
140 br i1 %a, label %cond.true, label %end
143 %tz = trunc i8 %z to i1
144 %zx = zext i1 %x to i32
145 %zy = zext i1 %y to i32
146 %zz = zext i1 %tz to i32
147 %mul = mul i32 %zx, %zy
148 %cond = xor i32 %mul, %zz
152 %p = phi i32 [ %cond, %cond.true ], [ -1, %entry ]
153 %r = icmp eq i32 %p, 0