Avoid emitting redundant materializations of integer constants
authorDan Gohman <gohman@apple.com>
Tue, 7 Oct 2008 22:03:27 +0000 (22:03 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 7 Oct 2008 22:03:27 +0000 (22:03 +0000)
for things like null pointers, which at this level aren't
different from regular integer constants.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57265 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/FastISel.cpp

index 17b37a34452100e3cc530d06e85e086a083b3c9e..f9cfeb1e972f6992bdbeb92f96edc5c44d4dedcf 100644 (file)
@@ -81,7 +81,9 @@ unsigned FastISel::getRegForValue(Value *V) {
   } else if (isa<AllocaInst>(V)) {
     Reg = TargetMaterializeAlloca(cast<AllocaInst>(V));
   } else if (isa<ConstantPointerNull>(V)) {
-    Reg = FastEmit_i(VT, VT, ISD::Constant, 0);
+    // Translate this as an integer zero so that it can be
+    // local-CSE'd with actual integer zeros.
+    Reg = getRegForValue(Constant::getNullValue(TD.getIntPtrType()));
   } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
     Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
 
@@ -95,8 +97,7 @@ unsigned FastISel::getRegForValue(Value *V) {
                                 APFloat::rmTowardZero) != APFloat::opOK) {
         APInt IntVal(IntBitWidth, 2, x);
 
-        unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(),
-                                         ISD::Constant, IntVal.getZExtValue());
+        unsigned IntegerReg = getRegForValue(ConstantInt::get(IntVal));
         if (IntegerReg != 0)
           Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
       }