1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
5 ; ((%x * %y) u/ %x) == %y
7 ; @llvm.umul.with.overflow(%x, %y) + extractvalue + not
9 define i1 @t0_basic(i8 %x, i8 %y) {
10 ; CHECK-LABEL: @t0_basic(
11 ; CHECK-NEXT: [[UMUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
12 ; CHECK-NEXT: [[UMUL_OV:%.*]] = extractvalue { i8, i1 } [[UMUL]], 1
13 ; CHECK-NEXT: [[UMUL_NOT_OV:%.*]] = xor i1 [[UMUL_OV]], true
14 ; CHECK-NEXT: ret i1 [[UMUL_NOT_OV]]
18 %r = icmp eq i8 %t1, %y
22 define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) {
23 ; CHECK-LABEL: @t1_vec(
24 ; CHECK-NEXT: [[UMUL:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.umul.with.overflow.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]])
25 ; CHECK-NEXT: [[UMUL_OV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[UMUL]], 1
26 ; CHECK-NEXT: [[UMUL_NOT_OV:%.*]] = xor <2 x i1> [[UMUL_OV]], <i1 true, i1 true>
27 ; CHECK-NEXT: ret <2 x i1> [[UMUL_NOT_OV]]
29 %t0 = mul <2 x i8> %x, %y
30 %t1 = udiv <2 x i8> %t0, %x
31 %r = icmp eq <2 x i8> %t1, %y
37 define i1 @t2_commutative(i8 %x) {
38 ; CHECK-LABEL: @t2_commutative(
39 ; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8()
40 ; CHECK-NEXT: [[UMUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y]])
41 ; CHECK-NEXT: [[UMUL_OV:%.*]] = extractvalue { i8, i1 } [[UMUL]], 1
42 ; CHECK-NEXT: [[UMUL_NOT_OV:%.*]] = xor i1 [[UMUL_OV]], true
43 ; CHECK-NEXT: ret i1 [[UMUL_NOT_OV]]
46 %t0 = mul i8 %y, %x ; swapped
48 %r = icmp eq i8 %t1, %y
52 define i1 @t3_commutative(i8 %x) {
53 ; CHECK-LABEL: @t3_commutative(
54 ; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8()
55 ; CHECK-NEXT: [[UMUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y]])
56 ; CHECK-NEXT: [[UMUL_OV:%.*]] = extractvalue { i8, i1 } [[UMUL]], 1
57 ; CHECK-NEXT: [[UMUL_NOT_OV:%.*]] = xor i1 [[UMUL_OV]], true
58 ; CHECK-NEXT: ret i1 [[UMUL_NOT_OV]]
61 %t0 = mul i8 %y, %x ; swapped
63 %r = icmp eq i8 %t1, %y
67 define i1 @t4_commutative(i8 %x) {
68 ; CHECK-LABEL: @t4_commutative(
69 ; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8()
70 ; CHECK-NEXT: [[UMUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y]])
71 ; CHECK-NEXT: [[UMUL_OV:%.*]] = extractvalue { i8, i1 } [[UMUL]], 1
72 ; CHECK-NEXT: [[UMUL_NOT_OV:%.*]] = xor i1 [[UMUL_OV]], true
73 ; CHECK-NEXT: ret i1 [[UMUL_NOT_OV]]
76 %t0 = mul i8 %y, %x ; swapped
78 %r = icmp eq i8 %y, %t1 ; swapped
84 declare void @use8(i8)
86 define i1 @t5_extrause0(i8 %x, i8 %y) {
87 ; CHECK-LABEL: @t5_extrause0(
88 ; CHECK-NEXT: [[UMUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
89 ; CHECK-NEXT: [[UMUL_VAL:%.*]] = extractvalue { i8, i1 } [[UMUL]], 0
90 ; CHECK-NEXT: [[UMUL_OV:%.*]] = extractvalue { i8, i1 } [[UMUL]], 1
91 ; CHECK-NEXT: [[UMUL_NOT_OV:%.*]] = xor i1 [[UMUL_OV]], true
92 ; CHECK-NEXT: call void @use8(i8 [[UMUL_VAL]])
93 ; CHECK-NEXT: ret i1 [[UMUL_NOT_OV]]
96 call void @use8(i8 %t0)
98 %r = icmp eq i8 %t1, %y
102 define i1 @t6_extrause1(i8 %x, i8 %y) {
103 ; CHECK-LABEL: @t6_extrause1(
104 ; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
105 ; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]]
106 ; CHECK-NEXT: call void @use8(i8 [[T1]])
107 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]]
108 ; CHECK-NEXT: ret i1 [[R]]
111 %t1 = udiv i8 %t0, %x
112 call void @use8(i8 %t1)
113 %r = icmp eq i8 %t1, %y
117 define i1 @t7_extrause2(i8 %x, i8 %y) {
118 ; CHECK-LABEL: @t7_extrause2(
119 ; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
120 ; CHECK-NEXT: call void @use8(i8 [[T0]])
121 ; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]]
122 ; CHECK-NEXT: call void @use8(i8 [[T1]])
123 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]]
124 ; CHECK-NEXT: ret i1 [[R]]
127 call void @use8(i8 %t0)
128 %t1 = udiv i8 %t0, %x
129 call void @use8(i8 %t1)
130 %r = icmp eq i8 %t1, %y
136 define i1 @n8_different_x(i8 %x0, i8 %x1, i8 %y) {
137 ; CHECK-LABEL: @n8_different_x(
138 ; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X0:%.*]], [[Y:%.*]]
139 ; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X1:%.*]]
140 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]]
141 ; CHECK-NEXT: ret i1 [[R]]
144 %t1 = udiv i8 %t0, %x1
145 %r = icmp eq i8 %t1, %y
149 define i1 @n9_different_y(i8 %x, i8 %y0, i8 %y1) {
150 ; CHECK-LABEL: @n9_different_y(
151 ; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y0:%.*]]
152 ; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]]
153 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y1:%.*]]
154 ; CHECK-NEXT: ret i1 [[R]]
157 %t1 = udiv i8 %t0, %x
158 %r = icmp eq i8 %t1, %y1
162 define i1 @n10_wrong_pred(i8 %x, i8 %y) {
163 ; CHECK-LABEL: @n10_wrong_pred(
164 ; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
165 ; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]]
166 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T1]], [[Y]]
167 ; CHECK-NEXT: ret i1 [[R]]
170 %t1 = udiv i8 %t0, %x
171 %r = icmp ult i8 %t1, %y