Skip to content

Commit 7306541

Browse files
committed
[InstCombine] add tests for zext-of-icmp; NFC
1 parent 315756b commit 7306541

File tree

1 file changed

+59
-12
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+59
-12
lines changed

llvm/test/Transforms/InstCombine/zext.ll

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ define i47 @sext_zext_apint2(i11 %A) {
179179
define i32 @masked_bit_set(i32 %x, i32 %y) {
180180
; CHECK-LABEL: @masked_bit_set(
181181
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], [[Y:%.*]]
182-
; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1
183-
; CHECK-NEXT: ret i32 [[TMP2]]
182+
; CHECK-NEXT: [[R:%.*]] = and i32 [[TMP1]], 1
183+
; CHECK-NEXT: ret i32 [[R]]
184184
;
185185
%sh1 = shl i32 1, %y
186186
%and = and i32 %sh1, %x
@@ -193,8 +193,8 @@ define <2 x i32> @masked_bit_clear(<2 x i32> %x, <2 x i32> %y) {
193193
; CHECK-LABEL: @masked_bit_clear(
194194
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[X:%.*]], <i32 -1, i32 -1>
195195
; CHECK-NEXT: [[TMP2:%.*]] = lshr <2 x i32> [[TMP1]], [[Y:%.*]]
196-
; CHECK-NEXT: [[TMP3:%.*]] = and <2 x i32> [[TMP2]], <i32 1, i32 1>
197-
; CHECK-NEXT: ret <2 x i32> [[TMP3]]
196+
; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[TMP2]], <i32 1, i32 1>
197+
; CHECK-NEXT: ret <2 x i32> [[R]]
198198
;
199199
%sh1 = shl <2 x i32> <i32 1, i32 1>, %y
200200
%and = and <2 x i32> %sh1, %x
@@ -207,8 +207,8 @@ define <2 x i32> @masked_bit_set_commute(<2 x i32> %px, <2 x i32> %y) {
207207
; CHECK-LABEL: @masked_bit_set_commute(
208208
; CHECK-NEXT: [[X:%.*]] = srem <2 x i32> <i32 42, i32 3>, [[PX:%.*]]
209209
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X]], [[Y:%.*]]
210-
; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 1, i32 1>
211-
; CHECK-NEXT: ret <2 x i32> [[TMP2]]
210+
; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[TMP1]], <i32 1, i32 1>
211+
; CHECK-NEXT: ret <2 x i32> [[R]]
212212
;
213213
%x = srem <2 x i32> <i32 42, i32 3>, %px ; thwart complexity-based canonicalization
214214
%sh1 = shl <2 x i32> <i32 1, i32 1>, %y
@@ -223,8 +223,8 @@ define i32 @masked_bit_clear_commute(i32 %px, i32 %y) {
223223
; CHECK-NEXT: [[X:%.*]] = srem i32 42, [[PX:%.*]]
224224
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X]], -1
225225
; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], [[Y:%.*]]
226-
; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], 1
227-
; CHECK-NEXT: ret i32 [[TMP3]]
226+
; CHECK-NEXT: [[R:%.*]] = and i32 [[TMP2]], 1
227+
; CHECK-NEXT: ret i32 [[R]]
228228
;
229229
%x = srem i32 42, %px ; thwart complexity-based canonicalization
230230
%sh1 = shl i32 1, %y
@@ -239,8 +239,8 @@ define i32 @masked_bit_set_use1(i32 %x, i32 %y) {
239239
; CHECK-NEXT: [[SH1:%.*]] = shl nuw i32 1, [[Y:%.*]]
240240
; CHECK-NEXT: call void @use32(i32 [[SH1]])
241241
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], [[Y]]
242-
; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1
243-
; CHECK-NEXT: ret i32 [[TMP2]]
242+
; CHECK-NEXT: [[R:%.*]] = and i32 [[TMP1]], 1
243+
; CHECK-NEXT: ret i32 [[R]]
244244
;
245245
%sh1 = shl i32 1, %y
246246
call void @use32(i32 %sh1)
@@ -294,8 +294,8 @@ define i32 @masked_bit_clear_use1(i32 %x, i32 %y) {
294294
; CHECK-NEXT: call void @use32(i32 [[SH1]])
295295
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], -1
296296
; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], [[Y]]
297-
; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], 1
298-
; CHECK-NEXT: ret i32 [[TMP3]]
297+
; CHECK-NEXT: [[R:%.*]] = and i32 [[TMP2]], 1
298+
; CHECK-NEXT: ret i32 [[R]]
299299
;
300300
%sh1 = shl i32 1, %y
301301
call void @use32(i32 %sh1)
@@ -642,3 +642,50 @@ define i64 @and_trunc_extra_use1_wider_src(i65 %x, i32 %y) {
642642
%z = zext i32 %a to i64
643643
ret i64 %z
644644
}
645+
646+
define i16 @zext_icmp_eq0_pow2(i32 %x) {
647+
; CHECK-LABEL: @zext_icmp_eq0_pow2(
648+
; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i16
649+
; CHECK-NEXT: [[TMP2:%.*]] = lshr i16 [[TMP1]], 2
650+
; CHECK-NEXT: [[TMP3:%.*]] = and i16 [[TMP2]], 1
651+
; CHECK-NEXT: [[Z:%.*]] = xor i16 [[TMP3]], 1
652+
; CHECK-NEXT: ret i16 [[Z]]
653+
;
654+
%m = and i32 %x, 4
655+
%i = icmp eq i32 %m, 0
656+
%z = zext i1 %i to i16
657+
ret i16 %z
658+
}
659+
660+
define i16 @zext_icmp_eq0_pow2_use1(i32 %x) {
661+
; CHECK-LABEL: @zext_icmp_eq0_pow2_use1(
662+
; CHECK-NEXT: [[M:%.*]] = and i32 [[X:%.*]], 4
663+
; CHECK-NEXT: call void @use32(i32 [[M]])
664+
; CHECK-NEXT: [[M_LOBIT:%.*]] = lshr exact i32 [[M]], 2
665+
; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[M_LOBIT]] to i16
666+
; CHECK-NEXT: [[Z:%.*]] = xor i16 [[TMP1]], 1
667+
; CHECK-NEXT: ret i16 [[Z]]
668+
;
669+
%m = and i32 %x, 4
670+
call void @use32(i32 %m)
671+
%i = icmp eq i32 %m, 0
672+
%z = zext i1 %i to i16
673+
ret i16 %z
674+
}
675+
676+
define i16 @zext_icmp_eq0_pow2_use2(i32 %x) {
677+
; CHECK-LABEL: @zext_icmp_eq0_pow2_use2(
678+
; CHECK-NEXT: [[M:%.*]] = and i32 [[X:%.*]], 4
679+
; CHECK-NEXT: [[I:%.*]] = icmp eq i32 [[M]], 0
680+
; CHECK-NEXT: call void @use1(i1 [[I]])
681+
; CHECK-NEXT: [[M_LOBIT:%.*]] = lshr exact i32 [[M]], 2
682+
; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[M_LOBIT]] to i16
683+
; CHECK-NEXT: [[Z:%.*]] = xor i16 [[TMP1]], 1
684+
; CHECK-NEXT: ret i16 [[Z]]
685+
;
686+
%m = and i32 %x, 4
687+
%i = icmp eq i32 %m, 0
688+
call void @use1(i1 %i)
689+
%z = zext i1 %i to i16
690+
ret i16 %z
691+
}

0 commit comments

Comments
 (0)