Skip to content

Commit 5d12274

Browse files
authored
[AArch64]: Added code for generating XAR instruction (#75085)
Fixes #61584
1 parent b3af755 commit 5d12274

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ class AArch64DAGToDAGISel : public SelectionDAGISel {
435435
bool trySelectCastFixedLengthToScalableVector(SDNode *N);
436436
bool trySelectCastScalableToFixedLengthVector(SDNode *N);
437437

438+
bool trySelectXAR(SDNode *N);
439+
438440
// Include the pieces autogenerated from the target description.
439441
#include "AArch64GenDAGISel.inc"
440442

@@ -4273,6 +4275,40 @@ bool AArch64DAGToDAGISel::trySelectCastScalableToFixedLengthVector(SDNode *N) {
42734275
return true;
42744276
}
42754277

4278+
bool AArch64DAGToDAGISel::trySelectXAR(SDNode *N) {
4279+
assert(N->getOpcode() == ISD::OR && "Expected OR instruction");
4280+
4281+
SDValue N0 = N->getOperand(0);
4282+
SDValue N1 = N->getOperand(1);
4283+
4284+
if (N0->getOpcode() != AArch64ISD::VSHL ||
4285+
N1->getOpcode() != AArch64ISD::VLSHR)
4286+
return false;
4287+
4288+
if (N0->getOperand(0) != N1->getOperand(0) ||
4289+
N1->getOperand(0)->getOpcode() != ISD::XOR)
4290+
return false;
4291+
4292+
SDValue XOR = N0.getOperand(0);
4293+
SDValue R1 = XOR.getOperand(0);
4294+
SDValue R2 = XOR.getOperand(1);
4295+
4296+
unsigned HsAmt = N0.getConstantOperandVal(1);
4297+
unsigned ShAmt = N1.getConstantOperandVal(1);
4298+
4299+
SDLoc DL = SDLoc(N0.getOperand(1));
4300+
SDValue Imm = CurDAG->getTargetConstant(
4301+
ShAmt, DL, N0.getOperand(1).getValueType(), false);
4302+
4303+
if (ShAmt + HsAmt != 64)
4304+
return false;
4305+
4306+
SDValue Ops[] = {R1, R2, Imm};
4307+
CurDAG->SelectNodeTo(N, AArch64::XAR, N0.getValueType(), Ops);
4308+
4309+
return true;
4310+
}
4311+
42764312
void AArch64DAGToDAGISel::Select(SDNode *Node) {
42774313
// If we have a custom node, we already have selected!
42784314
if (Node->isMachineOpcode()) {
@@ -4336,6 +4372,8 @@ void AArch64DAGToDAGISel::Select(SDNode *Node) {
43364372
case ISD::OR:
43374373
if (tryBitfieldInsertOp(Node))
43384374
return;
4375+
if (Subtarget->hasSHA3() && trySelectXAR(Node))
4376+
return;
43394377
break;
43404378

43414379
case ISD::EXTRACT_SUBVECTOR: {

llvm/test/CodeGen/AArch64/xar.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -mtriple=aarch64-none-eabi -mattr=+sha3 < %s | FileCheck --check-prefix=SHA3 %s
3+
; RUN: llc -mtriple=aarch64-none-eabi -mattr=-sha3 < %s | FileCheck --check-prefix=NOSHA3 %s
4+
5+
define <2 x i64> @xar(<2 x i64> %x, <2 x i64> %y) {
6+
; SHA3-LABEL: xar:
7+
; SHA3: // %bb.0:
8+
; SHA3-NEXT: xar v0.2d, v0.2d, v1.2d, #54
9+
; SHA3-NEXT: ret
10+
;
11+
; NOSHA3-LABEL: xar:
12+
; NOSHA3: // %bb.0:
13+
; NOSHA3-NEXT: eor v1.16b, v0.16b, v1.16b
14+
; NOSHA3-NEXT: shl v0.2d, v1.2d, #10
15+
; NOSHA3-NEXT: usra v0.2d, v1.2d, #54
16+
; NOSHA3-NEXT: ret
17+
%a = xor <2 x i64> %x, %y
18+
%b = call <2 x i64> @llvm.fshl.v2i64(<2 x i64> %a, <2 x i64> %a, <2 x i64> <i64 10, i64 10>)
19+
ret <2 x i64> %b
20+
}
21+
22+
declare <2 x i64> @llvm.fshl.v2i64(<2 x i64>, <2 x i64>, <2 x i64>)

0 commit comments

Comments
 (0)