Skip to content

Commit 9caca72

Browse files
committed
[AArch64][GlobalISel] Use the look-through constant helper for the shift s32->s64 custom legalization.
Almost NFC, except it catches more cases and gives a 0.1% CTMark -O0 size win.
1 parent d104e58 commit 9caca72

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,16 +710,14 @@ bool AArch64LegalizerInfo::legalizeShlAshrLshr(
710710
// If the shift amount is a G_CONSTANT, promote it to a 64 bit type so the
711711
// imported patterns can select it later. Either way, it will be legal.
712712
Register AmtReg = MI.getOperand(2).getReg();
713-
auto *CstMI = MRI.getVRegDef(AmtReg);
714-
assert(CstMI && "expected to find a vreg def");
715-
if (CstMI->getOpcode() != TargetOpcode::G_CONSTANT)
713+
auto VRegAndVal = getConstantVRegValWithLookThrough(AmtReg, MRI);
714+
if (!VRegAndVal)
716715
return true;
717716
// Check the shift amount is in range for an immediate form.
718-
unsigned Amount = CstMI->getOperand(1).getCImm()->getZExtValue();
717+
int64_t Amount = VRegAndVal->Value;
719718
if (Amount > 31)
720719
return true; // This will have to remain a register variant.
721-
assert(MRI.getType(AmtReg).getSizeInBits() == 32);
722-
auto ExtCst = MIRBuilder.buildZExt(LLT::scalar(64), AmtReg);
720+
auto ExtCst = MIRBuilder.buildConstant(LLT::scalar(64), Amount);
723721
MI.getOperand(2).setReg(ExtCst.getReg(0));
724722
return true;
725723
}

llvm/test/CodeGen/AArch64/GlobalISel/legalize-unmerge-values.mir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ body: |
2424
; CHECK-LABEL: name: test_unmerge_s4
2525
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
2626
; CHECK: [[UV:%[0-9]+]]:_(s8), [[UV1:%[0-9]+]]:_(s8), [[UV2:%[0-9]+]]:_(s8), [[UV3:%[0-9]+]]:_(s8) = G_UNMERGE_VALUES [[COPY]](s32)
27-
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
27+
; CHECK: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 4
2828
; CHECK: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[UV]](s8)
29-
; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[ZEXT]], [[C]](s32)
29+
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
30+
; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[ZEXT]], [[C1]](s64)
3031
; CHECK: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[UV]](s8)
3132
; CHECK: [[ANYEXT1:%[0-9]+]]:_(s64) = G_ANYEXT [[LSHR]](s32)
3233
; CHECK: $x0 = COPY [[ANYEXT]](s64)

0 commit comments

Comments
 (0)