Skip to content

Commit 064f507

Browse files
[ARM] Prefer MUL to MULS on some implementations
MULS adversely affects performance on many implementations. Where this is the case, we prefer not to shrink MUL to MULS.
1 parent df05512 commit 064f507

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

llvm/lib/Target/ARM/ARMFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,13 @@ def FeatureAvoidPartialCPSR : SubtargetFeature<"avoid-partial-cpsr",
398398
"AvoidCPSRPartialUpdate", "true",
399399
"Avoid CPSR partial update for OOO execution">;
400400

401+
/// FeatureAvoidMULS - If true, codegen would avoid using the MULS instruction,
402+
/// prefering the thumb2 MUL which doesn't set flags.
403+
def FeatureAvoidMULS : SubtargetFeature<"avoid-muls",
404+
"AvoidMULS", "true",
405+
"Avoid MULS instructions for M class cores">;
406+
407+
401408
/// Disable +1 predication cost for instructions updating CPSR.
402409
/// Enabled for Cortex-A57.
403410
/// True if disable +1 predication cost for instructions updating CPSR. Enabled for Cortex-A57.

llvm/lib/Target/ARM/ARMProcessors.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def : ProcessorModel<"cortex-m33", CortexM4Model, [ARMv8mMainline,
360360
FeatureHasSlowFPVFMx,
361361
FeatureUseMISched,
362362
FeatureHasNoBranchPredictor,
363+
FeatureAvoidMULS,
363364
FeatureFixCMSE_CVE_2021_35465]>;
364365

365366
def : ProcessorModel<"star-mc1", CortexM4Model, [ARMv8mMainline,

llvm/lib/Target/ARM/Thumb2SizeReduction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,9 @@ Thumb2SizeReduce::ReduceTo2Addr(MachineBasicBlock &MBB, MachineInstr *MI,
755755
Register Reg1 = MI->getOperand(1).getReg();
756756
// t2MUL is "special". The tied source operand is second, not first.
757757
if (MI->getOpcode() == ARM::t2MUL) {
758+
// MULS can be slower than MUL
759+
if (!MinimizeSize && STI->avoidMULS())
760+
return false;
758761
Register Reg2 = MI->getOperand(2).getReg();
759762
// Early exit if the regs aren't all low regs.
760763
if (!isARMLowRegister(Reg0) || !isARMLowRegister(Reg1)

llvm/test/CodeGen/Thumb2/avoidmuls.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ body: |
6363
6464
...
6565
# CHECK-LABEL: test
66-
# CHECK: tMUL
67-
# CHECK-NOT: t2MUL
66+
# CHECK: t2MUL
67+
# CHECK-NOT: tMUL

0 commit comments

Comments
 (0)