Index: src/IceTargetLoweringARM32.cpp |
diff --git a/src/IceTargetLoweringARM32.cpp b/src/IceTargetLoweringARM32.cpp |
index 0322a7e54ef60c6a77ff3599f78f52998d4a1620..4139fb8b951b9bc6b3bb581e24f1930367f7d3c7 100644 |
--- a/src/IceTargetLoweringARM32.cpp |
+++ b/src/IceTargetLoweringARM32.cpp |
@@ -3349,7 +3349,10 @@ void TargetARM32::lowerBr(const InstBr *Instr) { |
} |
void TargetARM32::lowerCall(const InstCall *Instr) { |
- Operand *CallTarget = Instr->getCallTarget(); |
+ // Note: Keep original call target. This allows us to call the correct |
+ // postamble helper, even if the CallTarget gets modified during lowering. |
+ Operand *OrigCallTarget = Instr->getCallTarget(); |
+ Operand *CallTarget = OrigCallTarget; |
if (Instr->isTargetHelperCall()) { |
auto TargetHelperPreamble = ARM32HelpersPreamble.find(CallTarget); |
if (TargetHelperPreamble != ARM32HelpersPreamble.end()) { |
@@ -3474,12 +3477,9 @@ void TargetARM32::lowerCall(const InstCall *Instr) { |
} |
} |
- // Allow ConstantRelocatable to be left alone as a direct call, but force |
- // other constants like ConstantInteger32 to be in a register and make it an |
- // indirect call. |
- if (!llvm::isa<ConstantRelocatable>(CallTarget)) { |
- CallTarget = legalize(CallTarget, Legal_Reg); |
- } |
+ // Note: To allow far calls, even for constant relocatables, we force |
+ // the call target into a register, and make an indirect call. |
+ CallTarget = legalizeToReg(CallTarget); |
// Copy arguments to be passed in registers to the appropriate registers. |
for (auto &FPArg : FPArgs) { |
@@ -3530,7 +3530,7 @@ void TargetARM32::lowerCall(const InstCall *Instr) { |
} |
if (Instr->isTargetHelperCall()) { |
- auto TargetHelpersPostamble = ARM32HelpersPostamble.find(CallTarget); |
+ auto TargetHelpersPostamble = ARM32HelpersPostamble.find(OrigCallTarget); |
if (TargetHelpersPostamble != ARM32HelpersPostamble.end()) { |
(this->*TargetHelpersPostamble->second)(Instr); |
} |