1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define i64 @test0(i64 %x) {
7 ; CHECK-NEXT: [[A:%.*]] = icmp eq i64 [[X:%.*]], 0
8 ; CHECK-NEXT: br i1 [[A]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
10 ; CHECK-NEXT: br i1 false, label [[UNREACHABLE:%.*]], label [[EXIT]]
12 ; CHECK-NEXT: br label [[EXIT]]
14 ; CHECK-NEXT: [[C:%.*]] = phi i64 [ 0, [[START:%.*]] ], [ 1, [[NON_ZERO]] ], [ 2, [[UNREACHABLE]] ]
15 ; CHECK-NEXT: ret i64 [[C]]
18 %a = icmp eq i64 %x, 0
19 br i1 %a, label %exit, label %non_zero
22 %b = icmp eq i64 %x, 0
23 br i1 %b, label %unreachable, label %exit
29 %c = phi i64 [ 0, %start ], [ 1, %non_zero ], [ 2, %unreachable ]
33 define i64 @test1(i64 %x) {
34 ; CHECK-LABEL: @test1(
36 ; CHECK-NEXT: [[A:%.*]] = icmp eq i64 [[X:%.*]], 0
37 ; CHECK-NEXT: br i1 [[A]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
39 ; CHECK-NEXT: br i1 true, label [[EXIT]], label [[UNREACHABLE:%.*]]
41 ; CHECK-NEXT: br label [[EXIT]]
43 ; CHECK-NEXT: [[C:%.*]] = phi i64 [ 0, [[START:%.*]] ], [ [[X]], [[NON_ZERO]] ], [ 0, [[UNREACHABLE]] ]
44 ; CHECK-NEXT: ret i64 [[C]]
47 %a = icmp eq i64 %x, 0
48 br i1 %a, label %exit, label %non_zero
51 %b = icmp ugt i64 %x, 0
52 br i1 %b, label %exit, label %unreachable
58 %c = phi i64 [ 0, %start ], [ %x, %non_zero ], [ 0, %unreachable ]
62 define i1 @test2(i64 %x, i1 %y) {
63 ; CHECK-LABEL: @test2(
65 ; CHECK-NEXT: [[A:%.*]] = icmp eq i64 [[X:%.*]], 0
66 ; CHECK-NEXT: br i1 [[A]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
68 ; CHECK-NEXT: br i1 [[Y:%.*]], label [[ONE:%.*]], label [[TWO:%.*]]
70 ; CHECK-NEXT: br label [[MAINBLOCK:%.*]]
72 ; CHECK-NEXT: br label [[MAINBLOCK]]
74 ; CHECK-NEXT: br label [[EXIT]]
76 ; CHECK-NEXT: [[RES:%.*]] = phi i1 [ false, [[MAINBLOCK]] ], [ true, [[START:%.*]] ]
77 ; CHECK-NEXT: ret i1 [[RES]]
80 %a = icmp eq i64 %x, 0
81 br i1 %a, label %exit, label %non_zero
84 br i1 %y, label %one, label %two
93 %p = phi i64 [ %x, %one ], [ 42, %two ]
94 %cmp = icmp eq i64 %p, 0
98 %res = phi i1 [ %cmp, %mainblock ], [ 1, %start ]
103 ; The code below exposed a bug similar to the one exposed by D60846, see the commit 6ea477590085.
104 ; In a nutshell, we should not replace %result.0 with 0 here.
106 define zeroext i8 @update_phi_query_loc_in_recursive_call(ptr nocapture readonly %p){
107 ; CHECK-LABEL: @update_phi_query_loc_in_recursive_call(
109 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
111 ; CHECK-NEXT: [[RESULT_0:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[CONV2:%.*]], [[FOR_BODY:%.*]] ]
112 ; CHECK-NEXT: [[SHIFT_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ 1, [[FOR_BODY]] ]
113 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[SHIFT_0]], 0
114 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP:%.*]]
115 ; CHECK: for.cond.cleanup:
116 ; CHECK-NEXT: ret i8 [[RESULT_0]]
118 ; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[P:%.*]], align 1
119 ; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[TMP0]] to i32
120 ; CHECK-NEXT: [[MUL:%.*]] = shl nuw nsw i32 [[SHIFT_0]], 3
121 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[CONV]], [[MUL]]
122 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[SHL]] to i8
123 ; CHECK-NEXT: [[CONV2]] = or i8 [[RESULT_0]], [[TMP1]]
124 ; CHECK-NEXT: br label [[FOR_COND]]
129 for.cond: ; preds = %for.body, %entry
130 %result.0 = phi i8 [ 0, %entry ], [ %conv2, %for.body ]
131 %shift.0 = phi i32 [ 0, %entry ], [ 1, %for.body ]
132 %cmp = icmp eq i32 %shift.0, 0
133 br i1 %cmp, label %for.body, label %for.cond.cleanup
135 for.cond.cleanup: ; preds = %for.cond
138 for.body: ; preds = %for.cond
139 %0 = load i8, ptr %p, align 1
140 %conv = zext i8 %0 to i32
141 %mul = shl nuw nsw i32 %shift.0, 3
142 %shl = shl nuw nsw i32 %conv, %mul
143 %1 = trunc i32 %shl to i8
144 %conv2 = or i8 %result.0, %1
145 %inc = add nuw nsw i32 %shift.0, 1
149 define i1 @freeze_nonzero(i8 %x, i8 %mask) {
150 ; CHECK-LABEL: @freeze_nonzero(
151 ; CHECK-NEXT: [[Y:%.*]] = or i8 [[X:%.*]], [[MASK:%.*]]
152 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[Y]], 0
153 ; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
155 ; CHECK-NEXT: ret i1 false
157 ; CHECK-NEXT: ret i1 false
160 %c = icmp ne i8 %y, 0
161 br i1 %c, label %A, label %B
164 %c2 = icmp eq i8 %fr, 0