1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i32 @sterix(i32, i8, i64) {
5 ; CHECK-LABEL: @sterix(
7 ; CHECK-NEXT: [[CONV:%.*]] = zext i32 [[TMP0:%.*]] to i64
8 ; CHECK-NEXT: [[CONV1:%.*]] = sext i8 [[TMP1:%.*]] to i32
9 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[CONV1]], 1945964878
10 ; CHECK-NEXT: [[SH_PROM:%.*]] = trunc i64 [[TMP2:%.*]] to i32
11 ; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[MUL]], [[SH_PROM]]
12 ; CHECK-NEXT: [[CONV2:%.*]] = zext i32 [[SHR]] to i64
13 ; CHECK-NEXT: [[MUL3:%.*]] = mul nuw nsw i64 [[CONV]], [[CONV2]]
14 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt i64 [[MUL3]], 4294967295
15 ; CHECK-NEXT: br i1 [[TMP3]], label [[LOR_END:%.*]], label [[LOR_RHS:%.*]]
17 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[MUL3]], [[TMP2]]
18 ; CHECK-NEXT: [[CONV4:%.*]] = trunc i64 [[AND]] to i32
19 ; CHECK-NEXT: [[TOBOOL7:%.*]] = icmp eq i32 [[CONV4]], 0
20 ; CHECK-NEXT: [[PHITMP:%.*]] = zext i1 [[TOBOOL7]] to i32
21 ; CHECK-NEXT: br label [[LOR_END]]
23 ; CHECK-NEXT: [[TMP4:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[PHITMP]], [[LOR_RHS]] ]
24 ; CHECK-NEXT: ret i32 [[TMP4]]
27 %conv = zext i32 %0 to i64
28 %conv1 = sext i8 %1 to i32
29 %mul = mul i32 %conv1, 1945964878
30 %sh_prom = trunc i64 %2 to i32
31 %shr = lshr i32 %mul, %sh_prom
32 %conv2 = zext i32 %shr to i64
33 %mul3 = mul nuw nsw i64 %conv, %conv2
34 %conv6 = and i64 %mul3, 4294967295
35 %tobool = icmp ne i64 %conv6, %mul3
36 br i1 %tobool, label %lor.end, label %lor.rhs
39 %and = and i64 %2, %mul3
40 %conv4 = trunc i64 %and to i32
41 %tobool7 = icmp ne i32 %conv4, 0
42 %lnot = xor i1 %tobool7, true
46 %3 = phi i1 [ true, %entry ], [ %lnot, %lor.rhs ]
47 %conv8 = zext i1 %3 to i32
51 ; https://bugs.llvm.org/show_bug.cgi?id=33765
53 @glob = external global i16
55 define void @PR33765(i8 %beth) {
56 ; CHECK-LABEL: @PR33765(
57 ; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[BETH:%.*]] to i32
58 ; CHECK-NEXT: br i1 false, label [[IF_THEN9:%.*]], label [[IF_THEN9]]
60 ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[CONV]], [[CONV]]
61 ; CHECK-NEXT: [[TINKY:%.*]] = load i16, i16* @glob, align 2
62 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[MUL]] to i16
63 ; CHECK-NEXT: [[CONV14:%.*]] = and i16 [[TINKY]], [[TMP1]]
64 ; CHECK-NEXT: store i16 [[CONV14]], i16* @glob, align 2
65 ; CHECK-NEXT: ret void
67 %conv = zext i8 %beth to i32
68 %mul = mul nuw nsw i32 %conv, %conv
69 %conv3 = and i32 %mul, 255
70 %tobool8 = icmp ne i32 %mul, %conv3
71 br i1 %tobool8, label %if.then9, label %if.then9
74 %tinky = load i16, i16* @glob
75 %conv13 = sext i16 %tinky to i32
76 %and = and i32 %mul, %conv13
77 %conv14 = trunc i32 %and to i16
78 store i16 %conv14, i16* @glob
82 ; Repro case for bug involving mutating a list while
87 define i16 @iter_breaker(i16 %a, i16 %b) {
88 ; CHECK-LABEL: @iter_breaker(
89 ; CHECK-NEXT: [[UMUL:%.*]] = call { i16, i1 } @llvm.umul.with.overflow.i16(i16 [[A:%.*]], i16 [[B:%.*]])
90 ; CHECK-NEXT: [[UMUL_VALUE:%.*]] = extractvalue { i16, i1 } [[UMUL]], 0
91 ; CHECK-NEXT: [[DID_OVF:%.*]] = extractvalue { i16, i1 } [[UMUL]], 1
92 ; CHECK-NEXT: br i1 [[DID_OVF]], label [[RET1:%.*]], label [[RET2:%.*]]
94 ; CHECK-NEXT: [[TRUNC_REMAIN:%.*]] = trunc i16 [[UMUL_VALUE]] to i8
95 ; CHECK-NEXT: [[VAL:%.*]] = call i16 @aux(i8 [[TRUNC_REMAIN]])
96 ; CHECK-NEXT: ret i16 [[VAL]]
98 ; CHECK-NEXT: ret i16 [[UMUL_VALUE]]
100 %a_wide = zext i16 %a to i32
101 %b_wide = zext i16 %b to i32
102 %mul_wide = mul i32 %a_wide, %b_wide ; uses of %mul_wide will be iterated
104 %trunc_remain = trunc i32 %mul_wide to i8 ; this use will be replaced w/ new value
105 ; when iteration visits it, switching
106 ; iteration to the uses of new value
108 %trunc_unnecessary = trunc i32 %mul_wide to i16 ; uses of %trunc_unnecessary will have
109 ; been updated to uses of new value
111 %did_ovf = icmp ugt i32 %mul_wide, 65535
112 br i1 %did_ovf, label %ret1, label %ret2
115 %val = call i16 @aux(i8 %trunc_remain)
119 ret i16 %trunc_unnecessary ; crash visiting this use after corrupting iterator