Skip to content

Commit f425418

Browse files
committed
[InstCombine] Add tests for 'partial' bswap patterns
As mentioned on PR47191, if we're bswap'ing some bytes and the zero'ing the remainder we can perform this as a bswap+mask which helps us match 'partial' bswaps as a first step towards folding into a more complex bswap pattern.
1 parent 052c5bf commit f425418

File tree

1 file changed

+47
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+47
-0
lines changed

llvm/test/Transforms/InstCombine/bswap.ll

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,53 @@ define i8 @PR39793_bswap_u32_as_u16_trunc(i32 %0) {
345345
ret i8 %7
346346
}
347347

348+
define i64 @bswap_and_mask_0(i64 %0) {
349+
; CHECK-LABEL: @bswap_and_mask_0(
350+
; CHECK-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP0:%.*]], 56
351+
; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP0]], 56
352+
; CHECK-NEXT: [[TMP4:%.*]] = or i64 [[TMP2]], [[TMP3]]
353+
; CHECK-NEXT: ret i64 [[TMP4]]
354+
;
355+
%2 = lshr i64 %0, 56
356+
%3 = shl i64 %0, 56
357+
%4 = or i64 %2, %3
358+
ret i64 %4
359+
}
360+
361+
define i64 @bswap_and_mask_1(i64 %0) {
362+
; CHECK-LABEL: @bswap_and_mask_1(
363+
; CHECK-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP0:%.*]], 56
364+
; CHECK-NEXT: [[TMP3:%.*]] = lshr i64 [[TMP0]], 40
365+
; CHECK-NEXT: [[TMP4:%.*]] = and i64 [[TMP3]], 65280
366+
; CHECK-NEXT: [[TMP5:%.*]] = or i64 [[TMP4]], [[TMP2]]
367+
; CHECK-NEXT: ret i64 [[TMP5]]
368+
;
369+
%2 = lshr i64 %0, 56
370+
%3 = lshr i64 %0, 40
371+
%4 = and i64 %3, 65280
372+
%5 = or i64 %4, %2
373+
ret i64 %5
374+
}
375+
376+
define i64 @bswap_and_mask_2(i64 %0) {
377+
; CHECK-LABEL: @bswap_and_mask_2(
378+
; CHECK-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP0:%.*]], 56
379+
; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP0]], 56
380+
; CHECK-NEXT: [[TMP4:%.*]] = or i64 [[TMP2]], [[TMP3]]
381+
; CHECK-NEXT: [[TMP5:%.*]] = shl i64 [[TMP0]], 40
382+
; CHECK-NEXT: [[TMP6:%.*]] = and i64 [[TMP5]], 71776119061217280
383+
; CHECK-NEXT: [[TMP7:%.*]] = or i64 [[TMP4]], [[TMP6]]
384+
; CHECK-NEXT: ret i64 [[TMP7]]
385+
;
386+
%2 = lshr i64 %0, 56
387+
%3 = shl i64 %0, 56
388+
%4 = or i64 %2, %3
389+
%5 = shl i64 %0, 40
390+
%6 = and i64 %5, 71776119061217280
391+
%7 = or i64 %4, %6
392+
ret i64 %7
393+
}
394+
348395
define i32 @shuf_4bytes(<4 x i8> %x) {
349396
; CHECK-LABEL: @shuf_4bytes(
350397
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i8> [[X:%.*]] to i32

0 commit comments

Comments
 (0)