diff options
author | Chris Lattner <sabre@nondot.org> | 2003-10-19 00:26:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-10-19 00:26:11 +0000 |
commit | a81fc68f8e318aca3d04a3026f19f3f271458972 (patch) | |
tree | b2fbe78024531c28740a8509435ac6b732965765 /lib | |
parent | 547eaefb0e56e197a1694c47f2e955a0df4d6c68 (diff) | |
download | llvm-a81fc68f8e318aca3d04a3026f19f3f271458972.tar.gz llvm-a81fc68f8e318aca3d04a3026f19f3f271458972.tar.bz2 llvm-a81fc68f8e318aca3d04a3026f19f3f271458972.tar.xz |
Fix bug: Jello/2003-10-18-PHINode-ConstantExpr-CondCode-Failure.llx
This also fixes miscompilation of 176.gcc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9249 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/X86/InstSelectSimple.cpp | 30 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelSimple.cpp | 30 |
2 files changed, 42 insertions, 18 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp index f9b949811b..ca59109f40 100644 --- a/lib/Target/X86/InstSelectSimple.cpp +++ b/lib/Target/X86/InstSelectSimple.cpp @@ -490,7 +490,7 @@ void ISel::SelectPHINodes() { // Loop over all of the PHI nodes in the LLVM basic block... unsigned NumPHIs = 0; for (BasicBlock::const_iterator I = BB->begin(); - PHINode *PN = (PHINode*)dyn_cast<PHINode>(I); ++I) { + PHINode *PN = const_cast<PHINode*>(dyn_cast<PHINode>(I)); ++I) { // Create a new machine instr PHI node, and insert it. unsigned PHIReg = getReg(*PN); @@ -521,15 +521,27 @@ void ISel::SelectPHINodes() { ValReg = EntryIt->second; } else { - // Get the incoming value into a virtual register. If it is not - // already available in a virtual register, insert the computation - // code into PredMBB + // Get the incoming value into a virtual register. // - MachineBasicBlock::iterator PI = PredMBB->end(); - while (PI != PredMBB->begin() && - TII.isTerminatorInstr((*(PI-1))->getOpcode())) - --PI; - ValReg = getReg(PN->getIncomingValue(i), PredMBB, PI); + Value *Val = PN->getIncomingValue(i); + + // If this is a constant or GlobalValue, we may have to insert code + // into the basic block to compute it into a virtual register. + if (isa<Constant>(Val) || isa<GlobalValue>(Val)) { + // Because we don't want to clobber any values which might be in + // physical registers with the computation of this constant (which + // might be arbitrarily complex if it is a constant expression), + // just insert the computation at the top of the basic block. + MachineBasicBlock::iterator PI = PredMBB->begin(); + + // Skip over any PHI nodes though! + while (PI != PredMBB->end() && (*PI)->getOpcode() == X86::PHI) + ++PI; + + ValReg = getReg(Val, PredMBB, PI); + } else { + ValReg = getReg(Val); + } // Remember that we inserted a value for this PHI for this predecessor PHIValues.insert(EntryIt, std::make_pair(PredMBB, ValReg)); diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp index f9b949811b..ca59109f40 100644 --- a/lib/Target/X86/X86ISelSimple.cpp +++ b/lib/Target/X86/X86ISelSimple.cpp @@ -490,7 +490,7 @@ void ISel::SelectPHINodes() { // Loop over all of the PHI nodes in the LLVM basic block... unsigned NumPHIs = 0; for (BasicBlock::const_iterator I = BB->begin(); - PHINode *PN = (PHINode*)dyn_cast<PHINode>(I); ++I) { + PHINode *PN = const_cast<PHINode*>(dyn_cast<PHINode>(I)); ++I) { // Create a new machine instr PHI node, and insert it. unsigned PHIReg = getReg(*PN); @@ -521,15 +521,27 @@ void ISel::SelectPHINodes() { ValReg = EntryIt->second; } else { - // Get the incoming value into a virtual register. If it is not - // already available in a virtual register, insert the computation - // code into PredMBB + // Get the incoming value into a virtual register. // - MachineBasicBlock::iterator PI = PredMBB->end(); - while (PI != PredMBB->begin() && - TII.isTerminatorInstr((*(PI-1))->getOpcode())) - --PI; - ValReg = getReg(PN->getIncomingValue(i), PredMBB, PI); + Value *Val = PN->getIncomingValue(i); + + // If this is a constant or GlobalValue, we may have to insert code + // into the basic block to compute it into a virtual register. + if (isa<Constant>(Val) || isa<GlobalValue>(Val)) { + // Because we don't want to clobber any values which might be in + // physical registers with the computation of this constant (which + // might be arbitrarily complex if it is a constant expression), + // just insert the computation at the top of the basic block. + MachineBasicBlock::iterator PI = PredMBB->begin(); + + // Skip over any PHI nodes though! + while (PI != PredMBB->end() && (*PI)->getOpcode() == X86::PHI) + ++PI; + + ValReg = getReg(Val, PredMBB, PI); + } else { + ValReg = getReg(Val); + } // Remember that we inserted a value for this PHI for this predecessor PHIValues.insert(EntryIt, std::make_pair(PredMBB, ValReg)); |