[llvm-commits] CVS: llvm/lib/Target/X86/InstSelectSimple.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Mar 30 13:11:03 PST 2004


Changes in directory llvm/lib/Target/X86:

InstSelectSimple.cpp updated: 1.196 -> 1.197

---
Log message:

Fix a fairly major performance problem.  If a PHI node had a constant as 
an incoming value from a block, the selector would evaluate the constant
at the TOP of the block instead of at the end of the block.  This made the
live range for the constant span the entire block, increasing register 
pressure needlessly.


---
Diffs of the changes:  (+18 -11)

Index: llvm/lib/Target/X86/InstSelectSimple.cpp
diff -u llvm/lib/Target/X86/InstSelectSimple.cpp:1.196 llvm/lib/Target/X86/InstSelectSimple.cpp:1.197
--- llvm/lib/Target/X86/InstSelectSimple.cpp:1.196	Thu Mar 18 11:01:26 2004
+++ llvm/lib/Target/X86/InstSelectSimple.cpp	Tue Mar 30 13:10:12 2004
@@ -597,17 +597,24 @@
           // 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);
+            if (isa<ConstantExpr>(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 {
+              // Simple constants get emitted at the end of the basic block,
+              // before any terminator instructions.  We "know" that the code to
+              // move a constant into a register will never clobber any flags.
+              ValReg = getReg(Val, PredMBB, PredMBB->getFirstTerminator());
+            }
           } else {
             ValReg = getReg(Val);
           }





More information about the llvm-commits mailing list