[PATCH] D137069: [AArch64] Support not only SHL but also SRL and SRA for ((X shift C) - Y) + Z --> (Z - Y) + (X shift C)
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 31 04:24:22 PDT 2022
bcl5980 created this revision.
bcl5980 added reviewers: dmgreen, efriedma, paulwalker-arm.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
bcl5980 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Followup rG325a3083b5b24 <https://reviews.llvm.org/rG325a3083b5b24fd0635fb5a49566dd573afc55ef>
Add SRL and SRA support
https://reviews.llvm.org/D137069
Files:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/addsub.ll
Index: llvm/test/CodeGen/AArch64/addsub.ll
===================================================================
--- llvm/test/CodeGen/AArch64/addsub.ll
+++ llvm/test/CodeGen/AArch64/addsub.ll
@@ -711,9 +711,8 @@
define i32 @commute_subop0_lshr(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: commute_subop0_lshr:
; CHECK: // %bb.0:
-; CHECK-NEXT: lsr w8, w0, #3
-; CHECK-NEXT: sub w8, w8, w1
-; CHECK-NEXT: add w0, w8, w2
+; CHECK-NEXT: sub w8, w2, w1
+; CHECK-NEXT: add w0, w8, w0, lsr #3
; CHECK-NEXT: ret
%lshr = lshr i32 %x, 3
%sub = sub i32 %lshr, %y
@@ -725,9 +724,8 @@
define i32 @commute_subop0_ashr(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: commute_subop0_ashr:
; CHECK: // %bb.0:
-; CHECK-NEXT: asr w8, w0, #3
-; CHECK-NEXT: sub w8, w8, w1
-; CHECK-NEXT: add w0, w8, w2
+; CHECK-NEXT: sub w8, w2, w1
+; CHECK-NEXT: add w0, w8, w0, asr #3
; CHECK-NEXT: ret
%ashr = ashr i32 %x, 3
%sub = sub i32 %ashr, %y
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -16854,15 +16854,15 @@
return SDValue();
}
-// ((X >> C) - Y) + Z --> (Z - Y) + (X >> C)
+// ((X shift C) - Y) + Z --> (Z - Y) + (X shift C)
static SDValue performAddCombineSubShift(SDNode *N, SDValue SUB, SDValue Z,
SelectionDAG &DAG) {
auto IsOneUseShiftC = [&](SDValue Shift) {
if (!Shift.hasOneUse())
return false;
- // TODO: support SRL and SRA also
- if (Shift.getOpcode() != ISD::SHL)
+ if (Shift.getOpcode() != ISD::SHL && Shift.getOpcode() != ISD::SRL &&
+ Shift.getOpcode() != ISD::SRA)
return false;
if (!isa<ConstantSDNode>(Shift.getOperand(1)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137069.471957.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221031/5f443a66/attachment.bin>
More information about the llvm-commits
mailing list