[llvm] [AArch64] Utilize `XAR` for certain vector rotates (PR #137629)
Rajveer Singh Bharadwaj via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 06:14:20 PDT 2025
https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/137629
>From c8e32e03aeccee5d2772f5248c04e647a8833f96 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 | 36 ++++++++++++++-----
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 40944e3d43d6b..c58f50dcfb3ea 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -13,6 +13,7 @@
#include "AArch64MachineFunctionInfo.h"
#include "AArch64TargetMachine.h"
#include "MCTargetDesc/AArch64AddressingModes.h"
+#include "MCTargetDesc/AArch64MCTargetDesc.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/CodeGen/ISDOpcodes.h"
#include "llvm/CodeGen/SelectionDAGISel.h"
@@ -4558,9 +4559,19 @@ 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));
+ SDValue Zero =
+ CurDAG->getConstant(0, DL, N1->getOperand(0).getValueType());
+ R1 = N1->getOperand(0);
+ R2 = Zero;
+ } else {
+ R1 = N0.getOperand(1);
+ R2 = N1.getOperand(1);
+ }
APInt ShlAmt, ShrAmt;
if (!ISD::isConstantSplatVector(N0.getOperand(2).getNode(), ShlAmt) ||
@@ -4574,7 +4585,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 +4602,20 @@ 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));
+ SDValue Zero = CurDAG->getConstant(0, DL, N1->getOperand(0).getValueType());
+ R1 = N1->getOperand(0);
+ R2 = Zero;
+ } 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