[PATCH] D146637: [InstCombine] Try to recognize bswap pattern when calling funnel shifts
Jun Zhang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 23 01:06:07 PDT 2023
junaire updated this revision to Diff 507635.
junaire added a comment.
Update existing tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146637/new/
https://reviews.llvm.org/D146637
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/bswap.ll
llvm/test/Transforms/InstCombine/fsh.ll
Index: llvm/test/Transforms/InstCombine/fsh.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fsh.ll
+++ llvm/test/Transforms/InstCombine/fsh.ll
@@ -672,8 +672,9 @@
define i32 @fshl_mask_args_same2(i32 %a) {
; CHECK-LABEL: @fshl_mask_args_same2(
-; CHECK-NEXT: [[T1:%.*]] = shl i32 [[A:%.*]], 8
-; CHECK-NEXT: [[T2:%.*]] = and i32 [[T1]], 65280
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[A:%.*]] to i16
+; CHECK-NEXT: [[REV:%.*]] = shl i16 [[TRUNC]], 8
+; CHECK-NEXT: [[T2:%.*]] = zext i16 [[REV]] to i32
; CHECK-NEXT: ret i32 [[T2]]
;
%t1 = and i32 %a, 255
@@ -683,8 +684,8 @@
define i32 @fshl_mask_args_same3(i32 %a) {
; CHECK-LABEL: @fshl_mask_args_same3(
-; CHECK-NEXT: [[T2:%.*]] = shl i32 [[A:%.*]], 24
-; CHECK-NEXT: ret i32 [[T2]]
+; CHECK-NEXT: [[REV:%.*]] = shl i32 [[A:%.*]], 24
+; CHECK-NEXT: ret i32 [[REV]]
;
%t1 = and i32 %a, 255
%t2 = call i32 @llvm.fshl.i32(i32 %t1, i32 %t1, i32 24)
Index: llvm/test/Transforms/InstCombine/bswap.ll
===================================================================
--- llvm/test/Transforms/InstCombine/bswap.ll
+++ llvm/test/Transforms/InstCombine/bswap.ll
@@ -932,17 +932,7 @@
define i64 @PR60690_call_fshl(i64 %result) {
; CHECK-LABEL: @PR60690_call_fshl(
-; CHECK-NEXT: [[AND_I:%.*]] = lshr i64 [[RESULT:%.*]], 8
-; CHECK-NEXT: [[SHR_I:%.*]] = and i64 [[AND_I]], 71777214294589695
-; CHECK-NEXT: [[AND1_I:%.*]] = shl i64 [[RESULT]], 8
-; CHECK-NEXT: [[SHL_I:%.*]] = and i64 [[AND1_I]], -71777214294589696
-; CHECK-NEXT: [[OR_I:%.*]] = or i64 [[SHR_I]], [[SHL_I]]
-; CHECK-NEXT: [[AND_I7:%.*]] = shl i64 [[OR_I]], 16
-; CHECK-NEXT: [[SHL_I8:%.*]] = and i64 [[AND_I7]], -281470681808896
-; CHECK-NEXT: [[AND1_I9:%.*]] = lshr i64 [[OR_I]], 16
-; CHECK-NEXT: [[SHR_I10:%.*]] = and i64 [[AND1_I9]], 281470681808895
-; CHECK-NEXT: [[OR_I11:%.*]] = or i64 [[SHL_I8]], [[SHR_I10]]
-; CHECK-NEXT: [[OR_I12:%.*]] = tail call i64 @llvm.fshl.i64(i64 [[OR_I11]], i64 [[OR_I11]], i64 32)
+; CHECK-NEXT: [[OR_I12:%.*]] = call i64 @llvm.bswap.i64(i64 [[RESULT:%.*]])
; CHECK-NEXT: ret i64 [[OR_I12]]
;
%and.i = lshr i64 %result, 8
@@ -962,17 +952,7 @@
define i64 @PR60690_call_fshr(i64 %result) {
; CHECK-LABEL: @PR60690_call_fshr(
-; CHECK-NEXT: [[AND_I:%.*]] = lshr i64 [[RESULT:%.*]], 8
-; CHECK-NEXT: [[SHR_I:%.*]] = and i64 [[AND_I]], 71777214294589695
-; CHECK-NEXT: [[AND1_I:%.*]] = shl i64 [[RESULT]], 8
-; CHECK-NEXT: [[SHL_I:%.*]] = and i64 [[AND1_I]], -71777214294589696
-; CHECK-NEXT: [[OR_I:%.*]] = or i64 [[SHR_I]], [[SHL_I]]
-; CHECK-NEXT: [[AND_I7:%.*]] = shl i64 [[OR_I]], 16
-; CHECK-NEXT: [[SHL_I8:%.*]] = and i64 [[AND_I7]], -281470681808896
-; CHECK-NEXT: [[AND1_I9:%.*]] = lshr i64 [[OR_I]], 16
-; CHECK-NEXT: [[SHR_I10:%.*]] = and i64 [[AND1_I9]], 281470681808895
-; CHECK-NEXT: [[OR_I11:%.*]] = or i64 [[SHL_I8]], [[SHR_I10]]
-; CHECK-NEXT: [[OR_I12:%.*]] = call i64 @llvm.fshl.i64(i64 [[OR_I11]], i64 [[OR_I11]], i64 32)
+; CHECK-NEXT: [[OR_I12:%.*]] = call i64 @llvm.bswap.i64(i64 [[RESULT:%.*]])
; CHECK-NEXT: ret i64 [[OR_I12]]
;
%and.i = lshr i64 %result, 8
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1783,6 +1783,10 @@
return BinaryOperator::CreateLShr(Op1,
ConstantExpr::getSub(WidthC, ShAmtC));
+ if (Instruction *BitOp =
+ matchBSwapOrBitReverse(*II, /*MatchBSwaps*/ true,
+ /*MatchBitReversals*/ true))
+ return BitOp;
// fshl i16 X, X, 8 --> bswap i16 X (reduce to more-specific form)
if (Op0 == Op1 && BitWidth == 16 && match(ShAmtC, m_SpecificInt(8))) {
Module *Mod = II->getModule();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146637.507635.patch
Type: text/x-patch
Size: 4007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230323/e8b5df49/attachment.bin>
More information about the llvm-commits
mailing list