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

Chris Lattner lattner at cs.uiuc.edu
Fri Jan 21 15:07:04 PST 2005



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.308 -> 1.309
---
Log message:

Handle comparisons of gep instructions that have different typed indices
as long as they are the same size.


---
Diffs of the changes:  (+9 -5)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.308 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.309
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.308	Wed Jan 19 15:50:18 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Fri Jan 21 17:06:49 2005
@@ -2244,9 +2244,9 @@
       unsigned DiffOperand = 0;     // The operand that differs.
       for (unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)
         if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {
-          if (GEPLHS->getOperand(i)->getType() != 
-                     GEPRHS->getOperand(i)->getType()) {
-            // Irreconsilable differences.
+          if (GEPLHS->getOperand(i)->getType()->getPrimitiveSize() != 
+                     GEPRHS->getOperand(i)->getType()->getPrimitiveSize()) {
+            // Irreconcilable differences.
             NumDifferences = 2;
             break;
           } else {
@@ -2259,8 +2259,12 @@
         return ReplaceInstUsesWith(I, // No comparison is needed here.
                                  ConstantBool::get(Cond == Instruction::SetEQ));
       else if (NumDifferences == 1) {
-        return new SetCondInst(Cond, GEPLHS->getOperand(DiffOperand),
-                               GEPRHS->getOperand(DiffOperand));
+        Value *LHSV = GEPLHS->getOperand(DiffOperand);
+        Value *RHSV = GEPRHS->getOperand(DiffOperand);
+        if (LHSV->getType() != RHSV->getType())
+          LHSV = InsertNewInstBefore(new CastInst(LHSV, RHSV->getType(),
+                                                  LHSV->getName()+".c"), I);
+          return new SetCondInst(Cond, LHSV, RHSV);
       }
     }
 






More information about the llvm-commits mailing list