Skip to content

Commit 003bcad

Browse files
authored
[ARM] Always lower direct calls as direct when the outliner is enabled (#66434)
The indirect lowering hinders the outliner's ability to see that sequences are in fact common, since the sequence similarity is rendered opaque by the register callee. The size savings from making them indirect seems to be dwarfed by the outliner's savings from de-duplication. rdar://115178034 rdar://115459865
1 parent 06e1bca commit 003bcad

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

llvm/lib/CodeGen/TargetPassConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,9 @@ void TargetPassConfig::addMachinePasses() {
12411241
addPass(&LiveDebugValuesID);
12421242
addPass(&MachineSanitizerBinaryMetadataID);
12431243

1244+
if (EnableMachineOutliner == RunOutliner::NeverOutline)
1245+
TM->Options.EnableMachineOutliner = false;
1246+
12441247
if (TM->Options.EnableMachineOutliner &&
12451248
getOptLevel() != CodeGenOptLevel::None &&
12461249
EnableMachineOutliner != RunOutliner::NeverOutline) {

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,14 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
23952395
return isa<Instruction>(U) &&
23962396
cast<Instruction>(U)->getParent() == BB;
23972397
}) > 2;
2398+
// The indirect call lowering hinders the MachineOutliner's ability to
2399+
// recognize common sequences. The resulting indirect calls all have the
2400+
// same target, but the outliner can't tell this a priori, since the
2401+
// branch target is turned into a register operand, and those can't (yet?)
2402+
// be assumed to have the same value at runtime.
2403+
const TargetOptions &Options = DAG.getTarget().Options;
2404+
if (Options.EnableMachineOutliner)
2405+
PreferIndirect = false;
23982406
}
23992407
}
24002408
if (isTailCall) {

llvm/test/CodeGen/ARM/minsize-call-cse.ll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
; RUN: llc < %s | FileCheck %s
1+
; RUN: llc < %s | FileCheck %s --check-prefixes=OUTLINER,CHECK
2+
; RUN: llc -enable-machine-outliner=always < %s | FileCheck %s --check-prefixes=OUTLINER,CHECK
3+
; RUN: llc -enable-machine-outliner=never < %s | FileCheck %s --check-prefixes=INDIRECT,CHECK
24

35
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
46
target triple = "thumbv7m-arm-none-eabi"
57

68
; CHECK-LABEL: f:
7-
; CHECK: blx r
8-
; CHECK: blx r
9-
; CHECK: blx r
9+
; OUTLINER: bl g
10+
; OUTLINER: bl g
11+
; OUTLINER: bl g
12+
; INDIRECT: blx r
13+
; INDIRECT: blx r
14+
; INDIRECT: blx r
1015
define void @f() minsize optsize {
1116
entry:
1217
call void @g(i32 45, i32 66)

llvm/test/CodeGen/ARM/pr42062.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc -o - %s 2>&1 | FileCheck %s --implicit-check-not=error
2+
; RUN: llc -o - %s -enable-machine-outliner=never 2>&1 | FileCheck %s --implicit-check-not=error
33
target triple = "thumbv8m.base-arm-none-eabi"
44
@foo = external global i8
55
declare i32 @bar(ptr nocapture, i32, i32, ptr nocapture)

0 commit comments

Comments
 (0)