[llvm] [AArch64] Remove tryShiftAmountMod in favor of SelectShiftMask (PR #228753)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 11 11:58:38 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Deepak Shirke (deepakshirkem)
<details>
<summary>Changes</summary>
The earlier patches moved the shift-amount optimizations (AND mask, ADD/SUB mod, NEG, MVN, ROTR) into the `SelectShiftMask` ComplexPattern, so the variable shift/rotate instructions inherit them through the `Shift` multiclass for both SelectionDAG and GlobalISel. With that in place, `tryShiftAmountMod` is now redundant and this patch removes it along with its two call sites.
Completing the removal needed a few additions so the ComplexPattern path covers every case the old DAG routine did:
- `allUsesAreShiftAmounts` gates the `NEG`/`MVN` rewrite, so a multi-use `C - x` amount (e.g. one that is also stored) is shared instead of being recomputed as a separate `neg`/`mvn`.
- The matcher accepts the amount in an i32 or i64 register, with the NEG/NOT opcode taken from the node's own type and the threshold/modulus from the `ShiftWidth` template parameter.
- Peek-through patterns cover widened amounts: an i32 shift with an i64 amount (`shiftMask32In64`), and an i64 shift with an extended i32 amount (`shiftMask64In32`), via `zext`/`anyext`/`sext`. `allUsesAreShiftAmounts` also looks through these extends.
Fixes [#<!-- -->224245](https://github.com/llvm/llvm-project/issues/224245)
Depends on [#<!-- -->226579](https://github.com/llvm/llvm-project/pull/226579)
---
Patch is 23.60 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/228753.diff
3 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+47-141)
- (modified) llvm/lib/Target/AArch64/AArch64InstrFormats.td (+37)
- (modified) llvm/test/CodeGen/AArch64/shift-amount-mod.ll (+72-84)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index a4b276066931f..87240a647b135 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -447,7 +447,6 @@ class AArch64DAGToDAGISel : public SelectionDAGISel {
bool tryBitfieldExtractOp(SDNode *N);
bool tryBitfieldInsertOp(SDNode *N);
bool tryBitfieldInsertInZeroOp(SDNode *N);
- bool tryShiftAmountMod(SDNode *N);
bool tryReadRegister(SDNode *N);
bool tryWriteRegister(SDNode *N);
@@ -772,14 +771,46 @@ bool AArch64DAGToDAGISel::SelectInlineAsmMemoryOperand(
return true;
}
+// Returns true if every use of N is a variable shift (SHL/SRL/SRA/ROTR) that
+// uses N as its shift-amount operand. When that holds, folding N into the
+// shift amount (e.g. generating a NEG or MVN) is safe even with multiple
+// uses, because each shift only reads the low bits of the amount.
+static bool allUsesAreShiftAmounts(SDValue N) {
+ for (SDNode *User : N.getNode()->users()) {
+ switch (User->getOpcode()) {
+ case ISD::SHL:
+ case ISD::SRL:
+ case ISD::SRA:
+ case ISD::ROTR:
+ if (User->getOperand(1).getNode() != N.getNode())
+ return false;
+ break;
+ case ISD::ANY_EXTEND:
+ case ISD::ZERO_EXTEND:
+ case ISD::SIGN_EXTEND:
+ // A 32-bit shift amount may be widened to i64 before it reaches the
+ // shift; look through the extend to the ultimate users.
+ if (!allUsesAreShiftAmounts(SDValue(User, 0)))
+ return false;
+ break;
+ default:
+ return false;
+ }
+ }
+ return true;
+}
+
template <unsigned ShiftWidth>
bool AArch64DAGToDAGISel::SelectShiftMask(SDValue N, SDValue &ShAmt) {
// AArch64 shift instructions only use the low log2(ShiftWidth) bits of the
- // shift amount. If the shift amount has a redundant AND mask that covers
- // those bits, we can remove it. Return false if nothing was combined so
- // other patterns (e.g. zext/sext GPR32 → SUBREG_TO_REG) can match.
+ // shift amount. The matcher may run on a node wider or narrower than the
+ // shift result (an i32 amount widened to i64, or an i64 modulus reduced to
+ // an i32 subtract), so the redundancy threshold and modulus come from the
+ // ShiftWidth template parameter, while the NEG/NOT opcode follows the node's
+ // own type. Return false if nothing was combined so other patterns (e.g.
+ // zext/sext GPR32 -> SUBREG_TO_REG) can match.
if (N.getOpcode() == ISD::AND && isa<ConstantSDNode>(N.getOperand(1)) &&
- N.getValueType() == (ShiftWidth == 32 ? MVT::i32 : MVT::i64)) {
+ (N.getValueType() == MVT::i32 || N.getValueType() == MVT::i64)) {
uint64_t Mask = N.getConstantOperandVal(1);
// Remove AND if the mask covers at least the low log2(ShiftWidth) bits.
if ((unsigned)llvm::countr_one(Mask) >= Log2_32(ShiftWidth)) {
@@ -791,7 +822,7 @@ bool AArch64DAGToDAGISel::SelectShiftMask(SDValue N, SDValue &ShAmt) {
// to avoid the ADD/SUB. The low log2(ShiftWidth) bits are unchanged, so the
// shift can use X directly; the original ADD/SUB stays for any other users.
if ((N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) &&
- N.getValueType() == (ShiftWidth == 32 ? MVT::i32 : MVT::i64)) {
+ (N.getValueType() == MVT::i32 || N.getValueType() == MVT::i64)) {
uint64_t Imm;
if (isIntImmediate(N.getOperand(1).getNode(), Imm) &&
(Imm % ShiftWidth == 0)) {
@@ -802,15 +833,16 @@ bool AArch64DAGToDAGISel::SelectShiftMask(SDValue N, SDValue &ShAmt) {
// If shifting by N-X where N == 0 mod ShiftWidth, then just shift by -X
// to generate a NEG instead of a SUB from a constant.
- if (N.getOpcode() == ISD::SUB && N.hasOneUse() &&
- N.getValueType() == (ShiftWidth == 32 ? MVT::i32 : MVT::i64)) {
+ if (N.getOpcode() == ISD::SUB && allUsesAreShiftAmounts(N) &&
+ (N.getValueType() == MVT::i32 || N.getValueType() == MVT::i64)) {
uint64_t Imm;
if (isIntImmediate(N.getOperand(0).getNode(), Imm) && Imm != 0 &&
(Imm % ShiftWidth == 0)) {
SDLoc DL(N);
EVT VT = N.getValueType();
- unsigned NegOpc = (ShiftWidth == 32) ? AArch64::SUBWrr : AArch64::SUBXrr;
- unsigned ZeroReg = (ShiftWidth == 32) ? AArch64::WZR : AArch64::XZR;
+ bool Is32 = VT == MVT::i32;
+ unsigned NegOpc = Is32 ? AArch64::SUBWrr : AArch64::SUBXrr;
+ unsigned ZeroReg = Is32 ? AArch64::WZR : AArch64::XZR;
SDValue Zero =
CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, ZeroReg, VT);
MachineSDNode *Neg =
@@ -822,15 +854,16 @@ bool AArch64DAGToDAGISel::SelectShiftMask(SDValue N, SDValue &ShAmt) {
// If shifting by N-X where N == -1 mod ShiftWidth, then just shift by ~X
// to generate a NOT (MVN) instead of a SUB from a constant.
- if (N.getOpcode() == ISD::SUB && N.hasOneUse() &&
- N.getValueType() == (ShiftWidth == 32 ? MVT::i32 : MVT::i64)) {
+ if (N.getOpcode() == ISD::SUB && allUsesAreShiftAmounts(N) &&
+ (N.getValueType() == MVT::i32 || N.getValueType() == MVT::i64)) {
uint64_t Imm;
if (isIntImmediate(N.getOperand(0).getNode(), Imm) &&
(Imm % ShiftWidth == ShiftWidth - 1)) {
SDLoc DL(N);
EVT VT = N.getValueType();
- unsigned NotOpc = (ShiftWidth == 32) ? AArch64::ORNWrr : AArch64::ORNXrr;
- unsigned ZeroReg = (ShiftWidth == 32) ? AArch64::WZR : AArch64::XZR;
+ bool Is32 = VT == MVT::i32;
+ unsigned NotOpc = Is32 ? AArch64::ORNWrr : AArch64::ORNXrr;
+ unsigned ZeroReg = Is32 ? AArch64::WZR : AArch64::XZR;
SDValue Zero =
CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, ZeroReg, VT);
MachineSDNode *Not =
@@ -4194,131 +4227,6 @@ bool AArch64DAGToDAGISel::tryBitfieldInsertInZeroOp(SDNode *N) {
return true;
}
-/// tryShiftAmountMod - Take advantage of built-in mod of shift amount in
-/// variable shift/rotate instructions.
-bool AArch64DAGToDAGISel::tryShiftAmountMod(SDNode *N) {
- EVT VT = N->getValueType(0);
-
- unsigned Opc;
- switch (N->getOpcode()) {
- case ISD::ROTR:
- Opc = (VT == MVT::i32) ? AArch64::RORVWr : AArch64::RORVXr;
- break;
- case ISD::SHL:
- Opc = (VT == MVT::i32) ? AArch64::LSLVWr : AArch64::LSLVXr;
- break;
- case ISD::SRL:
- Opc = (VT == MVT::i32) ? AArch64::LSRVWr : AArch64::LSRVXr;
- break;
- case ISD::SRA:
- Opc = (VT == MVT::i32) ? AArch64::ASRVWr : AArch64::ASRVXr;
- break;
- default:
- return false;
- }
-
- uint64_t Size;
- uint64_t Bits;
- if (VT == MVT::i32) {
- Bits = 5;
- Size = 32;
- } else if (VT == MVT::i64) {
- Bits = 6;
- Size = 64;
- } else
- return false;
-
- SDValue ShiftAmt = N->getOperand(1);
- SDLoc DL(N);
- SDValue NewShiftAmt;
-
- // Skip over an extend of the shift amount.
- if (ShiftAmt->getOpcode() == ISD::ZERO_EXTEND ||
- ShiftAmt->getOpcode() == ISD::ANY_EXTEND)
- ShiftAmt = ShiftAmt->getOperand(0);
-
- if (ShiftAmt->getOpcode() == ISD::ADD || ShiftAmt->getOpcode() == ISD::SUB) {
- SDValue Add0 = ShiftAmt->getOperand(0);
- SDValue Add1 = ShiftAmt->getOperand(1);
- uint64_t Add0Imm;
- uint64_t Add1Imm;
- if (isIntImmediate(Add1, Add1Imm) && (Add1Imm % Size == 0)) {
- // If we are shifting by X+/-N where N == 0 mod Size, then just shift by X
- // to avoid the ADD/SUB.
- NewShiftAmt = Add0;
- } else if (ShiftAmt->getOpcode() == ISD::SUB &&
- isIntImmediate(Add0, Add0Imm) && Add0Imm != 0 &&
- (Add0Imm % Size == 0)) {
- // If we are shifting by N-X where N == 0 mod Size, then just shift by -X
- // to generate a NEG instead of a SUB from a constant.
- unsigned NegOpc;
- unsigned ZeroReg;
- EVT SubVT = ShiftAmt->getValueType(0);
- if (SubVT == MVT::i32) {
- NegOpc = AArch64::SUBWrr;
- ZeroReg = AArch64::WZR;
- } else {
- assert(SubVT == MVT::i64);
- NegOpc = AArch64::SUBXrr;
- ZeroReg = AArch64::XZR;
- }
- SDValue Zero =
- CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, ZeroReg, SubVT);
- MachineSDNode *Neg =
- CurDAG->getMachineNode(NegOpc, DL, SubVT, Zero, Add1);
- NewShiftAmt = SDValue(Neg, 0);
- } else if (ShiftAmt->getOpcode() == ISD::SUB &&
- isIntImmediate(Add0, Add0Imm) && (Add0Imm % Size == Size - 1)) {
- // If we are shifting by N-X where N == -1 mod Size, then just shift by ~X
- // to generate a NOT instead of a SUB from a constant.
- unsigned NotOpc;
- unsigned ZeroReg;
- EVT SubVT = ShiftAmt->getValueType(0);
- if (SubVT == MVT::i32) {
- NotOpc = AArch64::ORNWrr;
- ZeroReg = AArch64::WZR;
- } else {
- assert(SubVT == MVT::i64);
- NotOpc = AArch64::ORNXrr;
- ZeroReg = AArch64::XZR;
- }
- SDValue Zero =
- CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, ZeroReg, SubVT);
- MachineSDNode *Not =
- CurDAG->getMachineNode(NotOpc, DL, SubVT, Zero, Add1);
- NewShiftAmt = SDValue(Not, 0);
- } else
- return false;
- } else {
- // If the shift amount is masked with an AND, check that the mask covers the
- // bits that are implicitly ANDed off by the above opcodes and if so, skip
- // the AND.
- uint64_t MaskImm;
- if (!isOpcWithIntImmediate(ShiftAmt.getNode(), ISD::AND, MaskImm) &&
- !isOpcWithIntImmediate(ShiftAmt.getNode(), AArch64ISD::ANDS, MaskImm))
- return false;
-
- if ((unsigned)llvm::countr_one(MaskImm) < Bits)
- return false;
-
- NewShiftAmt = ShiftAmt->getOperand(0);
- }
-
- // Narrow/widen the shift amount to match the size of the shift operation.
- if (VT == MVT::i32)
- NewShiftAmt = narrowIfNeeded(CurDAG, NewShiftAmt);
- else if (VT == MVT::i64 && NewShiftAmt->getValueType(0) == MVT::i32) {
- SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, DL, MVT::i32);
- MachineSDNode *Ext = CurDAG->getMachineNode(AArch64::SUBREG_TO_REG, DL, VT,
- NewShiftAmt, SubReg);
- NewShiftAmt = SDValue(Ext, 0);
- }
-
- SDValue Ops[] = {N->getOperand(0), NewShiftAmt};
- CurDAG->SelectNodeTo(N, Opc, VT, Ops);
- return true;
-}
-
static bool checkCVTFixedPointOperandWithFBits(SelectionDAG *CurDAG, SDValue N,
SDValue &FixedPos,
unsigned RegWidth,
@@ -5291,8 +5199,6 @@ void AArch64DAGToDAGISel::Select(SDNode *Node) {
[[fallthrough]];
case ISD::ROTR:
case ISD::SHL:
- if (tryShiftAmountMod(Node))
- return;
break;
case ISD::OR:
diff --git a/llvm/lib/Target/AArch64/AArch64InstrFormats.td b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
index 1b334a605b600..4629262f05083 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrFormats.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
@@ -2785,6 +2785,17 @@ def shiftMask64 : ComplexPattern<i64, 1, "SelectShiftMask<64>", [], [], 0>;
def gi_shift_mask64 : GIComplexOperandMatcher<s64, "selectShiftMask<64>">,
GIComplexPatternEquiv<shiftMask64>;
+// A 32-bit shift reads only the low 5 bits of its amount, so the same masking
+// applies when that amount is held in an i64 register (e.g. a narrow shift
+// amount widened by sext/zext). Reuse the 32-bit matcher on an i64 node; the
+// widen pattern narrows the result with EXTRACT_SUBREG.
+def shiftMask32In64 : ComplexPattern<i64, 1, "SelectShiftMask<32>", [], [], 0>;
+
+// A 64-bit shift reads the low 6 bits of its amount; when that amount is an
+// i32 value widened to i64 (e.g. a (64 - x) computed in i32 then zero/any/
+// sign-extended), run the 64-bit matcher on the i32 node and widen the result.
+def shiftMask64In32 : ComplexPattern<i32, 1, "SelectShiftMask<64>", [], [], 0>;
+
multiclass Shift<bits<2> shift_type, string asm, SDNode OpNode> {
def Wr : BaseShift<0b0, shift_type, GPR32, asm>;
@@ -2811,6 +2822,18 @@ multiclass Shift<bits<2> shift_type, string asm, SDNode OpNode> {
(!cast<Instruction>(NAME # "Xr") GPR64:$Rn,
(SUBREG_TO_REG GPR32:$Rm, sub_32))>;
+ // Peek through the widening when the i64 shift amount is an extended i32
+ // value that still carries a maskable AND or a (C - x) subtract.
+ def : Pat<(i64 (OpNode GPR64:$Rn, (i64 (zext (i32 shiftMask64In32:$Rm))))),
+ (!cast<Instruction>(NAME # "Xr") GPR64:$Rn,
+ (SUBREG_TO_REG shiftMask64In32:$Rm, sub_32))>;
+ def : Pat<(i64 (OpNode GPR64:$Rn, (i64 (anyext (i32 shiftMask64In32:$Rm))))),
+ (!cast<Instruction>(NAME # "Xr") GPR64:$Rn,
+ (SUBREG_TO_REG shiftMask64In32:$Rm, sub_32))>;
+ def : Pat<(i64 (OpNode GPR64:$Rn, (i64 (sext (i32 shiftMask64In32:$Rm))))),
+ (!cast<Instruction>(NAME # "Xr") GPR64:$Rn,
+ (SUBREG_TO_REG shiftMask64In32:$Rm, sub_32))>;
+
def : Pat<(i32 (OpNode GPR32:$Rn, shiftMask32:$Rm)),
(!cast<Instruction>(NAME # "Wr") GPR32:$Rn, shiftMask32:$Rm)>;
def : Pat<(i64 (OpNode GPR64:$Rn, shiftMask64:$Rm)),
@@ -2820,6 +2843,20 @@ multiclass Shift<bits<2> shift_type, string asm, SDNode OpNode> {
// peek through it and apply the 32-bit shift-amount masking.
def : Pat<(i32 (OpNode GPR32:$Rn, (i64 (zext (i32 shiftMask32:$Rm))))),
(!cast<Instruction>(NAME # "Wr") GPR32:$Rn, shiftMask32:$Rm)>;
+
+ // The same masking applies when the i32 shift amount is widened to i64 with
+ // any_extend or sign_extend (not just zero_extend).
+ def : Pat<(i32 (OpNode GPR32:$Rn, (i64 (anyext (i32 shiftMask32:$Rm))))),
+ (!cast<Instruction>(NAME # "Wr") GPR32:$Rn, shiftMask32:$Rm)>;
+ def : Pat<(i32 (OpNode GPR32:$Rn, (i64 (sext (i32 shiftMask32:$Rm))))),
+ (!cast<Instruction>(NAME # "Wr") GPR32:$Rn, shiftMask32:$Rm)>;
+
+ // A 32-bit shift may take an i64 shift amount that carries a redundant
+ // AND mask, e.g. an i8/i16 shift amount widened to i64. Strip the mask
+ // with the 32-bit matcher (shiftMask32In64) and narrow the result to i32.
+ def : Pat<(i32 (OpNode GPR32:$Rn, (i64 shiftMask32In64:$Rm))),
+ (!cast<Instruction>(NAME # "Wr") GPR32:$Rn,
+ (EXTRACT_SUBREG shiftMask32In64:$Rm, sub_32))>;
}
class ShiftAlias<string asm, Instruction inst, RegisterClass regtype>
diff --git a/llvm/test/CodeGen/AArch64/shift-amount-mod.ll b/llvm/test/CodeGen/AArch64/shift-amount-mod.ll
index d4f3e80e96dd1..1f7a702dae980 100644
--- a/llvm/test/CodeGen/AArch64/shift-amount-mod.ll
+++ b/llvm/test/CodeGen/AArch64/shift-amount-mod.ll
@@ -59,13 +59,12 @@ define void @modify32_shl_by_negated(ptr %valptr, i32 %shamt) nounwind {
define void @modify32_shl_by_negated_multi_use(ptr %valptr, i32 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify32_shl_by_negated_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr w8, [x0]
-; CHECK-NEXT: neg w9, w1
-; CHECK-NEXT: lsl w8, w8, w9
-; CHECK-NEXT: mov w9, #32 // =0x20
-; CHECK-NEXT: sub w9, w9, w1
-; CHECK-NEXT: str w8, [x0]
-; CHECK-NEXT: str w9, [x2]
+; CHECK-NEXT: mov w8, #32 // =0x20
+; CHECK-NEXT: ldr w9, [x0]
+; CHECK-NEXT: sub w8, w8, w1
+; CHECK-NEXT: lsl w9, w9, w8
+; CHECK-NEXT: str w9, [x0]
+; CHECK-NEXT: str w8, [x2]
; CHECK-NEXT: ret
%val = load i32, ptr %valptr
%negshamt = sub i32 32, %shamt
@@ -126,13 +125,12 @@ define void @modify64_shl_by_negated(ptr %valptr, i64 %shamt) nounwind {
define void @modify64_shl_by_negated_multi_use(ptr %valptr, i64 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify64_shl_by_negated_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr x8, [x0]
-; CHECK-NEXT: neg x9, x1
-; CHECK-NEXT: lsl x8, x8, x9
-; CHECK-NEXT: mov w9, #64 // =0x40
-; CHECK-NEXT: sub x9, x9, x1
-; CHECK-NEXT: str x8, [x0]
-; CHECK-NEXT: str x9, [x2]
+; CHECK-NEXT: mov w8, #64 // =0x40
+; CHECK-NEXT: ldr x9, [x0]
+; CHECK-NEXT: sub x8, x8, x1
+; CHECK-NEXT: lsl x9, x9, x8
+; CHECK-NEXT: str x9, [x0]
+; CHECK-NEXT: str x8, [x2]
; CHECK-NEXT: ret
%val = load i64, ptr %valptr
%negshamt = sub i64 64, %shamt
@@ -196,13 +194,12 @@ define void @modify32_lshr_by_negated(ptr %valptr, i32 %shamt) nounwind {
define void @modify32_lshr_by_negated_multi_use(ptr %valptr, i32 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify32_lshr_by_negated_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr w8, [x0]
-; CHECK-NEXT: neg w9, w1
-; CHECK-NEXT: lsr w8, w8, w9
-; CHECK-NEXT: mov w9, #32 // =0x20
-; CHECK-NEXT: sub w9, w9, w1
-; CHECK-NEXT: str w8, [x0]
-; CHECK-NEXT: str w9, [x2]
+; CHECK-NEXT: mov w8, #32 // =0x20
+; CHECK-NEXT: ldr w9, [x0]
+; CHECK-NEXT: sub w8, w8, w1
+; CHECK-NEXT: lsr w9, w9, w8
+; CHECK-NEXT: str w9, [x0]
+; CHECK-NEXT: str w8, [x2]
; CHECK-NEXT: ret
%val = load i32, ptr %valptr
%negshamt = sub i32 32, %shamt
@@ -263,13 +260,12 @@ define void @modify64_lshr_by_negated(ptr %valptr, i64 %shamt) nounwind {
define void @modify64_lshr_by_negated_multi_use(ptr %valptr, i64 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify64_lshr_by_negated_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr x8, [x0]
-; CHECK-NEXT: neg x9, x1
-; CHECK-NEXT: lsr x8, x8, x9
-; CHECK-NEXT: mov w9, #64 // =0x40
-; CHECK-NEXT: sub x9, x9, x1
-; CHECK-NEXT: str x8, [x0]
-; CHECK-NEXT: str x9, [x2]
+; CHECK-NEXT: mov w8, #64 // =0x40
+; CHECK-NEXT: ldr x9, [x0]
+; CHECK-NEXT: sub x8, x8, x1
+; CHECK-NEXT: lsr x9, x9, x8
+; CHECK-NEXT: str x9, [x0]
+; CHECK-NEXT: str x8, [x2]
; CHECK-NEXT: ret
%val = load i64, ptr %valptr
%negshamt = sub i64 64, %shamt
@@ -333,13 +329,12 @@ define void @modify32_ashr_by_negated(ptr %valptr, i32 %shamt) nounwind {
define void @modify32_ashr_by_negated_multi_use(ptr %valptr, i32 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify32_ashr_by_negated_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr w8, [x0]
-; CHECK-NEXT: neg w9, w1
-; CHECK-NEXT: asr w8, w8, w9
-; CHECK-NEXT: mov w9, #32 // =0x20
-; CHECK-NEXT: sub w9, w9, w1
-; CHECK-NEXT: str w8, [x0]
-; CHECK-NEXT: str w9, [x2]
+; CHECK-NEXT: mov w8, #32 // =0x20
+; CHECK-NEXT: ldr w9, [x0]
+; CHECK-NEXT: sub w8, w8, w1
+; CHECK-NEXT: asr w9, w9, w8
+; CHECK-NEXT: str w9, [x0]
+; CHECK-NEXT: str w8, [x2]
; CHECK-NEXT: ret
%val = load i32, ptr %valptr
%negshamt = sub i32 32, %shamt
@@ -400,13 +395,12 @@ define void @modify64_ashr_by_negated(ptr %valptr, i64 %shamt) nounwind {
define void @modify64_ashr_by_negated_multi_use(ptr %valptr, i64 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify64_ashr_by_negated_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr x8, [x0]
-; CHECK-NEXT: neg x9, x1
-; CHECK-NEXT: asr x8, x8, x9
-; CHECK-NEXT: mov w9, #64 // =0x40
-; CHECK-NEXT: sub x9, x9, x1
-; CHECK-NEXT: str x8, [x0]
-; CHECK-NEXT: str x9, [x2]
+; CHECK-NEXT: mov w8, #64 // =0x40
+; CHECK-NEXT: ldr x9, [x0]
+; CHECK-NEXT: sub x8, x8, x1
+; CHECK-NEXT: asr x9, x9, x8
+; CHECK-NEXT: str x9, [x0]
+; CHECK-NEXT: str x8, [x2]
; CHECK-NEXT: ret
%val = load i64, ptr %valptr
%negshamt = sub i64 64, %shamt
@@ -474,13 +468,12 @@ define void @modify32_shl_by_complemented(ptr %valptr, i32 %shamt) nounwind {
define void @modify32_shl_by_complemented_multi_use(ptr %valptr, i32 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify32_shl_by_complemented_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr w8, [x0]
-; CHECK-NEXT: mvn w9, w1
-; CHECK-NEXT: lsl w8, w8, w9
-; CHECK-NEXT: mov w9, #31 // =0x1f
-; CHECK-NEXT: sub w9, w9, w1
-; CHECK-NEXT: str w8, [x0]
-; CHECK-NEXT: str w9, [x2]
+; CHECK-NEXT: mov w8, #31 // =0x1f
+; CHECK-NEXT: ldr w9, [x0]
+; CHECK-NEXT: sub w8, w8, w1
+; CHECK-NEXT: lsl w9, w9, w8
+; CHECK-NEXT: str w9, [x0]
+; CHECK-NEXT: str w8, [x2]
; CHECK-NEXT: ret
%val = load i32, ptr %valptr
%negshamt = sub i32 31, %shamt
@@ -541,13 +534,12 @@ define void @modify64_shl_by_complemented(ptr %valptr, i64 %shamt) nounwind {
define void @modify64_shl_by_complemented_multi_use(ptr %valptr, i64 %shamt, ptr %shamtptr) nounwind {
; CHECK-LABEL: modify64_shl_by_complemented_multi_use:
; CHECK: // %bb.0:
-; CHECK-NEXT: ldr x8, [x0]
-; C...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/228753
More information about the llvm-commits
mailing list