[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Jan 28 11:32:16 PST 2005



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.310 -> 1.311
---
Log message:

* add some DEBUG statements
* Properly compile this:

struct a {};
int test() {
  struct a b[2];
  if (&b[0] != &b[1])
    abort ();
  return 0;
}

to 'return 0', not abort().


---
Diffs of the changes:  (+10 -3)

 InstructionCombining.cpp |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.310 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.311
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.310	Sun Jan 23 14:26:55 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Fri Jan 28 13:32:01 2005
@@ -2198,14 +2198,17 @@
     // index is zero or not.
     if (Cond == Instruction::SetEQ || Cond == Instruction::SetNE) {
       Instruction *InVal = 0;
-      for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i) {
+      gep_type_iterator GTI = gep_type_begin(GEPLHS);
+      for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i, ++GTI) {
         bool EmitIt = true;
         if (Constant *C = dyn_cast<Constant>(GEPLHS->getOperand(i))) {
           if (isa<UndefValue>(C))  // undef index -> undef.
             return ReplaceInstUsesWith(I, UndefValue::get(I.getType()));
           if (C->isNullValue())
             EmitIt = false;
-          else if (isa<ConstantInt>(C))
+          else if (TD->getTypeSize(GTI.getIndexedType()) == 0) {
+            EmitIt = false;  // This is indexing into a zero sized array?
+          } else if (isa<ConstantInt>(C)) 
             return ReplaceInstUsesWith(I, // No comparison is needed here.
                                  ConstantBool::get(Cond == Instruction::SetNE));
         }
@@ -4902,7 +4905,9 @@
         AddUsesToWorkList(*I);
       ++NumDeadInst;
 
-      I->getParent()->getInstList().erase(I);
+      DEBUG(std::cerr << "IC: DCE: " << *I);
+
+      I->eraseFromParent();
       removeFromWorkList(I);
       continue;
     }
@@ -4929,6 +4934,8 @@
         }
       }
 
+      DEBUG(std::cerr << "IC: ConstFold to: " << *C << " from: " << *I);
+
       // Add operands to the worklist...
       AddUsesToWorkList(*I);
       ReplaceInstUsesWith(*I, C);






More information about the llvm-commits mailing list