[llvm] [AArch64] Utilize `XAR` for certain vector rotates (PR #137629)
Rajveer Singh Bharadwaj via llvm-commits
llvm-commits at lists.llvm.org
Sat May 3 05:58:37 PDT 2025
https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/137629
>From c14ca26d3eb87c78fa1aa4fda3822ed2d576baf5 Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer at icloud.com>
Date: Mon, 28 Apr 2025 18:42:32 +0530
Subject: [PATCH] [AArch64] Utilize `XAR` for certain vector rotates
Resolves #137162
For cases when there isn't any `XOR` in the transformation,
replace with a zero register.
---
.../Target/AArch64/AArch64ISelDAGToDAG.cpp | 47 +++++++++++++++----
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 40944e3d43d6b..ab60fa3fef02d 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -4558,9 +4558,27 @@ bool AArch64DAGToDAGISel::trySelectXAR(SDNode *N) {
!TLI->isAllActivePredicate(*CurDAG, N1.getOperand(0)))
return false;
- SDValue XOR = N0.getOperand(1);
- if (XOR.getOpcode() != ISD::XOR || XOR != N1.getOperand(1))
- return false;
+ SDValue R1, R2;
+ if (N0.getOperand(1).getOpcode() != ISD::XOR) {
+ if (N0.getOperand(1) != N1.getOperand(1))
+ return false;
+ SDLoc DL(N1->getOperand(0));
+ EVT VT = N1->getOperand(0).getValueType();
+
+ SDValue Zero = CurDAG->getTargetConstant(0, DL, MVT::i64);
+ SDNode *MOV = CurDAG->getMachineNode(AArch64::MOVIv2d_ns, DL, VT, Zero);
+ SDValue MOVIV = SDValue(MOV, 0);
+
+ SDValue ZSub = CurDAG->getTargetConstant(AArch64::zsub, DL, MVT::i64);
+ SDNode *SubRegToReg = CurDAG->getMachineNode(AArch64::SUBREG_TO_REG, DL,
+ MVT::i64, Zero, MOVIV, ZSub);
+
+ R1 = N1->getOperand(0);
+ R2 = SDValue(SubRegToReg, 0);
+ } else {
+ R1 = N0.getOperand(1);
+ R2 = N1.getOperand(1);
+ }
APInt ShlAmt, ShrAmt;
if (!ISD::isConstantSplatVector(N0.getOperand(2).getNode(), ShlAmt) ||
@@ -4574,7 +4592,7 @@ bool AArch64DAGToDAGISel::trySelectXAR(SDNode *N) {
SDValue Imm =
CurDAG->getTargetConstant(ShrAmt.getZExtValue(), DL, MVT::i32);
- SDValue Ops[] = {XOR.getOperand(0), XOR.getOperand(1), Imm};
+ SDValue Ops[] = {R1, R2, Imm};
if (auto Opc = SelectOpcodeFromVT<SelectTypeKind::Int>(
VT, {AArch64::XAR_ZZZI_B, AArch64::XAR_ZZZI_H, AArch64::XAR_ZZZI_S,
AArch64::XAR_ZZZI_D})) {
@@ -4591,13 +4609,24 @@ bool AArch64DAGToDAGISel::trySelectXAR(SDNode *N) {
N1->getOpcode() != AArch64ISD::VLSHR)
return false;
- if (N0->getOperand(0) != N1->getOperand(0) ||
- N1->getOperand(0)->getOpcode() != ISD::XOR)
+ if (N0->getOperand(0) != N1->getOperand(0))
return false;
- SDValue XOR = N0.getOperand(0);
- SDValue R1 = XOR.getOperand(0);
- SDValue R2 = XOR.getOperand(1);
+ SDValue R1, R2;
+ if (N1->getOperand(0)->getOpcode() != ISD::XOR) {
+ SDLoc DL(N1->getOperand(0));
+ EVT VT = N1->getOperand(0).getValueType();
+
+ SDValue Zero = CurDAG->getTargetConstant(0, DL, MVT::i64);
+ SDNode *MOV = CurDAG->getMachineNode(AArch64::MOVIv2d_ns, DL, VT, Zero);
+ SDValue MOVIV = SDValue(MOV, 0);
+ R1 = N1->getOperand(0);
+ R2 = MOVIV;
+ } else {
+ SDValue XOR = N0.getOperand(0);
+ R1 = XOR.getOperand(0);
+ R2 = XOR.getOperand(1);
+ }
unsigned HsAmt = N0.getConstantOperandVal(1);
unsigned ShAmt = N1.getConstantOperandVal(1);
More information about the llvm-commits
mailing list