mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-03 01:12:59 +00:00
IPRA: Fix RegMask calculation for alias registers
This patch fixes a very subtle bug in regmask calculation. Thanks to zan jyu Wong <zyfwong@gmail.com> for bringing this to notice. For example if CL is only clobbered than CH should not be marked clobbered but CX, RCX and ECX should be mark clobbered. Previously for each modified register all of its aliases are marked clobbered by markRegClobbred() in RegUsageInfoCollector.cpp but that is wrong because when CL is clobbered then MRI::isPhysRegModified() will return true for CL, CX, ECX, RCX which is correct behavior but then for CX, EXC, RCX we mark CH also clobbered as CH is aliased to CX,ECX,RCX so markRegClobbred() is not required because isPhysRegModified already take cares of proper aliasing register. A very simple test case has been added to verify this change. Please find relevant bug report here : http://llvm.org/PR28567 Patch by Vivek Pandya <vivekvpandya@gmail.com> Differential Revision: https://reviews.llvm.org/D22400 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276235 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
20e71624df
commit
fc02f97363
@ -57,10 +57,6 @@ public:
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
|
||||
static char ID;
|
||||
|
||||
private:
|
||||
void markRegClobbered(const TargetRegisterInfo *TRI, uint32_t *RegMask,
|
||||
unsigned PReg);
|
||||
};
|
||||
} // end of anonymous namespace
|
||||
|
||||
@ -76,13 +72,6 @@ FunctionPass *llvm::createRegUsageInfoCollector() {
|
||||
return new RegUsageInfoCollector();
|
||||
}
|
||||
|
||||
void RegUsageInfoCollector::markRegClobbered(const TargetRegisterInfo *TRI,
|
||||
uint32_t *RegMask, unsigned PReg) {
|
||||
// If PReg is clobbered then all of its alias are also clobbered.
|
||||
for (MCRegAliasIterator AI(PReg, TRI, true); AI.isValid(); ++AI)
|
||||
RegMask[*AI / 32] &= ~(1u << *AI % 32);
|
||||
}
|
||||
|
||||
void RegUsageInfoCollector::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<PhysicalRegisterUsageInfo>();
|
||||
AU.setPreservesAll();
|
||||
@ -116,7 +105,7 @@ bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) {
|
||||
|
||||
for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg)
|
||||
if (MRI->isPhysRegModified(PReg, true))
|
||||
markRegClobbered(TRI, &RegMask[0], PReg);
|
||||
RegMask[PReg / 32] &= ~(1u << PReg % 32);
|
||||
|
||||
if (!TargetFrameLowering::isSafeForNoCSROpt(F)) {
|
||||
const uint32_t *CallPreservedMask =
|
||||
|
12
test/CodeGen/X86/ipra-reg-alias.ll
Normal file
12
test/CodeGen/X86/ipra-reg-alias.ll
Normal file
@ -0,0 +1,12 @@
|
||||
; RUN: llc -enable-ipra -print-regusage -o /dev/null 2>&1 < %s | FileCheck %s
|
||||
target triple = "x86_64--"
|
||||
|
||||
define i8 @main(i8 %X) {
|
||||
%inc = add i8 %X, 1
|
||||
%inc2 = mul i8 %inc, 5
|
||||
; Here only CL is clobbred so CH should not be clobbred, but CX, ECX and RCX
|
||||
; should be clobbered.
|
||||
; CHECK: main Clobbered Registers: AH AL AX CL CX EAX ECX EFLAGS RAX RCX
|
||||
ret i8 %inc2
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user