Skip to content

Commit 68df06a

Browse files
authored
[Hexagon] Do not optimize address of another function's block (#101209)
When the constant extender optimization pass encounters an instruction that uses an extended address pointing to another function's block, avoid adding the instruction to the extender list for the current machine function. Fixes #99714
1 parent 1a5d892 commit 68df06a

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,10 @@ void HCE::recordExtender(MachineInstr &MI, unsigned OpNum) {
12231223
if (ER.Kind == MachineOperand::MO_GlobalAddress)
12241224
if (ER.V.GV->getName().empty())
12251225
return;
1226+
// Ignore block address that points to block in another function
1227+
if (ER.Kind == MachineOperand::MO_BlockAddress)
1228+
if (ER.V.BA->getFunction() != &(MI.getMF()->getFunction()))
1229+
return;
12261230
Extenders.push_back(ED);
12271231
}
12281232

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# REQUIRES: asserts
2+
# RUN: llc -march=hexagon -run-pass hexagon-cext-opt %s -o - | FileCheck %s
3+
4+
# Check that the HexagonConstantExtenders pass does not assert when block
5+
# addresses from different functions are used
6+
# CHECK-LABEL: name: wibble
7+
# CHECK: A2_tfrsi blockaddress(@baz
8+
# CHECK: A2_tfrsi blockaddress(@wibble
9+
10+
--- |
11+
target triple = "hexagon"
12+
13+
define dso_local void @baz() {
14+
bb:
15+
br label %bb1
16+
17+
bb1: ; preds = %bb
18+
%call = tail call fastcc i32 @wibble(i32 poison)
19+
ret void
20+
}
21+
22+
define internal fastcc i32 @wibble(i32 %arg) {
23+
bb:
24+
%call = tail call i32 @eggs(i32 noundef ptrtoint (ptr blockaddress(@baz, %bb1) to i32))
25+
br label %bb1
26+
27+
bb1: ; preds = %bb
28+
tail call void @baz.1(i32 noundef ptrtoint (ptr blockaddress(@wibble, %bb1) to i32))
29+
ret i32 %call
30+
}
31+
32+
declare i32 @eggs(i32 noundef) local_unnamed_addr
33+
34+
declare void @baz.1(i32 noundef) local_unnamed_addr
35+
36+
...
37+
---
38+
name: baz
39+
alignment: 16
40+
exposesReturnsTwice: false
41+
legalized: false
42+
regBankSelected: false
43+
selected: false
44+
failedISel: false
45+
tracksRegLiveness: true
46+
hasWinCFI: false
47+
callsEHReturn: false
48+
callsUnwindInit: false
49+
hasEHCatchret: false
50+
hasEHScopes: false
51+
hasEHFunclets: false
52+
isOutlined: false
53+
debugInstrRef: false
54+
failsVerification: false
55+
tracksDebugUserValues: false
56+
registers:
57+
- { id: 0, class: intregs, preferred-register: '' }
58+
liveins: []
59+
frameInfo:
60+
isFrameAddressTaken: false
61+
isReturnAddressTaken: false
62+
hasStackMap: false
63+
hasPatchPoint: false
64+
stackSize: 0
65+
offsetAdjustment: 0
66+
maxAlignment: 1
67+
adjustsStack: false
68+
hasCalls: false
69+
stackProtector: ''
70+
functionContext: ''
71+
maxCallFrameSize: 4294967295
72+
cvBytesOfCalleeSavedRegisters: 0
73+
hasOpaqueSPAdjustment: false
74+
hasVAStart: false
75+
hasMustTailInVarArgFunc: false
76+
hasTailCall: true
77+
isCalleeSavedInfoValid: false
78+
localFrameSize: 0
79+
savePoint: ''
80+
restorePoint: ''
81+
fixedStack: []
82+
stack: []
83+
entry_values: []
84+
callSites: []
85+
debugValueSubstitutions: []
86+
constants: []
87+
machineFunctionInfo: {}
88+
body: |
89+
bb.0.bb:
90+
successors: %bb.1(0x80000000)
91+
92+
bb.1.bb1 (ir-block-address-taken %ir-block.bb1):
93+
%0:intregs = IMPLICIT_DEF
94+
$r0 = COPY %0
95+
PS_tailcall_i @wibble, hexagoncsr, implicit $r0
96+
97+
...
98+
---
99+
name: wibble
100+
alignment: 16
101+
exposesReturnsTwice: false
102+
legalized: false
103+
regBankSelected: false
104+
selected: false
105+
failedISel: false
106+
tracksRegLiveness: true
107+
hasWinCFI: false
108+
callsEHReturn: false
109+
callsUnwindInit: false
110+
hasEHCatchret: false
111+
hasEHScopes: false
112+
hasEHFunclets: false
113+
isOutlined: false
114+
debugInstrRef: false
115+
failsVerification: false
116+
tracksDebugUserValues: false
117+
registers:
118+
- { id: 0, class: intregs, preferred-register: '' }
119+
- { id: 1, class: intregs, preferred-register: '' }
120+
- { id: 2, class: intregs, preferred-register: '' }
121+
- { id: 3, class: intregs, preferred-register: '' }
122+
- { id: 4, class: intregs, preferred-register: '' }
123+
liveins: []
124+
frameInfo:
125+
isFrameAddressTaken: false
126+
isReturnAddressTaken: false
127+
hasStackMap: false
128+
hasPatchPoint: false
129+
stackSize: 0
130+
offsetAdjustment: 0
131+
maxAlignment: 1
132+
adjustsStack: true
133+
hasCalls: true
134+
stackProtector: ''
135+
functionContext: ''
136+
maxCallFrameSize: 4294967295
137+
cvBytesOfCalleeSavedRegisters: 0
138+
hasOpaqueSPAdjustment: false
139+
hasVAStart: false
140+
hasMustTailInVarArgFunc: false
141+
hasTailCall: false
142+
isCalleeSavedInfoValid: false
143+
localFrameSize: 0
144+
savePoint: ''
145+
restorePoint: ''
146+
fixedStack: []
147+
stack: []
148+
entry_values: []
149+
callSites: []
150+
debugValueSubstitutions: []
151+
constants: []
152+
machineFunctionInfo: {}
153+
body: |
154+
bb.0.bb:
155+
successors: %bb.1(0x80000000)
156+
157+
%2:intregs = A2_tfrsi blockaddress(@baz, %ir-block.bb1)
158+
ADJCALLSTACKDOWN 0, 0, implicit-def $r29, implicit-def dead $r30, implicit $r31, implicit $r30, implicit $r29
159+
$r0 = COPY %2
160+
J2_call @eggs, hexagoncsr, implicit-def dead $pc, implicit-def dead $r31, implicit $r29, implicit $r0, implicit-def $r29, implicit-def $r0
161+
ADJCALLSTACKUP 0, 0, implicit-def dead $r29, implicit-def dead $r30, implicit-def dead $r31, implicit $r29
162+
%3:intregs = COPY $r0
163+
164+
bb.1.bb1 (ir-block-address-taken %ir-block.bb1):
165+
%4:intregs = A2_tfrsi blockaddress(@wibble, %ir-block.bb1)
166+
ADJCALLSTACKDOWN 0, 0, implicit-def $r29, implicit-def dead $r30, implicit $r31, implicit $r30, implicit $r29
167+
$r0 = COPY %4
168+
J2_call @baz.1, hexagoncsr, implicit-def dead $pc, implicit-def dead $r31, implicit $r29, implicit $r0, implicit-def $r29
169+
ADJCALLSTACKUP 0, 0, implicit-def dead $r29, implicit-def dead $r30, implicit-def dead $r31, implicit $r29
170+
$r0 = COPY %3
171+
PS_jmpret $r31, implicit-def dead $pc, implicit $r0
172+
173+
...

0 commit comments

Comments
 (0)