1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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: [[TMP3:%.*]] = icmp ult i64 [[MUL3]], 4294967296
17 ; CHECK-NEXT: br i1 [[TMP3]], label [[LOR_RHS:%.*]], label [[LOR_END:%.*]]
19 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[MUL3]], [[TMP2]]
20 ; CHECK-NEXT: [[CONV4:%.*]] = trunc i64 [[AND]] to i32
21 ; CHECK-NEXT: [[TOBOOL7_NOT:%.*]] = icmp eq i32 [[CONV4]], 0
22 ; CHECK-NEXT: [[PHITMP:%.*]] = zext i1 [[TOBOOL7_NOT]] to i32
23 ; CHECK-NEXT: br label [[LOR_END]]
25 ; CHECK-NEXT: [[TMP4:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[PHITMP]], [[LOR_RHS]] ]
26 ; CHECK-NEXT: ret i32 [[TMP4]]
29 %conv = zext i32 %0 to i64
30 %conv1 = sext i8 %1 to i32
31 %mul = mul i32 %conv1, 1945964878
32 %sh_prom = trunc i64 %2 to i32
33 %shr = lshr i32 %mul, %sh_prom
34 %conv2 = zext i32 %shr to i64
35 %mul3 = mul nuw nsw i64 %conv, %conv2
36 %conv6 = and i64 %mul3, 4294967295
37 %tobool = icmp ne i64 %conv6, %mul3
38 br i1 %tobool, label %lor.end, label %lor.rhs
41 %and = and i64 %2, %mul3
42 %conv4 = trunc i64 %and to i32
43 %tobool7 = icmp ne i32 %conv4, 0
44 %lnot = xor i1 %tobool7, true
48 %3 = phi i1 [ true, %entry ], [ %lnot, %lor.rhs ]
49 %conv8 = zext i1 %3 to i32
53 ; https://bugs.llvm.org/show_bug.cgi?id=33765
55 @glob = external global i16
57 define void @PR33765(i8 %beth) {
58 ; CHECK-LABEL: @PR33765(
59 ; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[BETH:%.*]] to i32
60 ; CHECK-NEXT: br i1 false, label [[IF_THEN9:%.*]], label [[IF_THEN9]]
62 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[CONV]], [[CONV]]
63 ; CHECK-NEXT: [[TINKY:%.*]] = load i16, i16* @glob, align 2
64 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[MUL]] to i16
65 ; CHECK-NEXT: [[CONV14:%.*]] = and i16 [[TINKY]], [[TMP1]]
66 ; CHECK-NEXT: store i16 [[CONV14]], i16* @glob, align 2
67 ; CHECK-NEXT: ret void
69 %conv = zext i8 %beth to i32
70 %mul = mul nuw nsw i32 %conv, %conv
71 %conv3 = and i32 %mul, 255
72 %tobool8 = icmp ne i32 %mul, %conv3
73 br i1 %tobool8, label %if.then9, label %if.then9
76 %tinky = load i16, i16* @glob
77 %conv13 = sext i16 %tinky to i32
78 %and = and i32 %mul, %conv13
79 %conv14 = trunc i32 %and to i16
80 store i16 %conv14, i16* @glob
84 ; Repro case for bug involving mutating a list while
89 define i16 @iter_breaker(i16 %a, i16 %b) {
90 ; CHECK-LABEL: @iter_breaker(
91 ; CHECK-NEXT: [[UMUL:%.*]] = call { i16, i1 } @llvm.umul.with.overflow.i16(i16 [[A:%.*]], i16 [[B:%.*]])
92 ; CHECK-NEXT: [[UMUL_VALUE:%.*]] = extractvalue { i16, i1 } [[UMUL]], 0
93 ; CHECK-NEXT: [[DID_OVF:%.*]] = extractvalue { i16, i1 } [[UMUL]], 1
94 ; CHECK-NEXT: br i1 [[DID_OVF]], label [[RET1:%.*]], label [[RET2:%.*]]
96 ; CHECK-NEXT: [[TRUNC_REMAIN:%.*]] = trunc i16 [[UMUL_VALUE]] to i8
97 ; CHECK-NEXT: [[VAL:%.*]] = call i16 @aux(i8 [[TRUNC_REMAIN]])
98 ; CHECK-NEXT: ret i16 [[VAL]]
100 ; CHECK-NEXT: ret i16 [[UMUL_VALUE]]
102 %a_wide = zext i16 %a to i32
103 %b_wide = zext i16 %b to i32
104 %mul_wide = mul i32 %a_wide, %b_wide ; uses of %mul_wide will be iterated
106 %trunc_remain = trunc i32 %mul_wide to i8 ; this use will be replaced w/ new value
107 ; when iteration visits it, switching
108 ; iteration to the uses of new value
110 %trunc_unnecessary = trunc i32 %mul_wide to i16 ; uses of %trunc_unnecessary will have
111 ; been updated to uses of new value
113 %did_ovf = icmp ugt i32 %mul_wide, 65535
114 br i1 %did_ovf, label %ret1, label %ret2
117 %val = call i16 @aux(i8 %trunc_remain)
121 ret i16 %trunc_unnecessary ; crash visiting this use after corrupting iterator
124 ; This miscompiled because of broken pattern matching.
126 define i1 @PR46561(i1 %a, i1 %x, i1 %y, i8 %z) {
127 ; CHECK-LABEL: @PR46561(
129 ; CHECK-NEXT: br i1 [[A:%.*]], label [[COND_TRUE:%.*]], label [[END:%.*]]
131 ; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
132 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[Z:%.*]], 1
133 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[TMP0]], 0
134 ; CHECK-NEXT: [[PHI_CMP:%.*]] = xor i1 [[TMP1]], [[MULBOOL]]
135 ; CHECK-NEXT: br label [[END]]
137 ; CHECK-NEXT: [[P:%.*]] = phi i1 [ [[PHI_CMP]], [[COND_TRUE]] ], [ false, [[ENTRY:%.*]] ]
138 ; CHECK-NEXT: ret i1 [[P]]
141 br i1 %a, label %cond.true, label %end
144 %tz = trunc i8 %z to i1
145 %zx = zext i1 %x to i32
146 %zy = zext i1 %y to i32
147 %zz = zext i1 %tz to i32
148 %mul = mul i32 %zx, %zy
149 %cond = xor i32 %mul, %zz
153 %p = phi i32 [ %cond, %cond.true ], [ -1, %entry ]
154 %r = icmp eq i32 %p, 0