diff options
author | Chris Lattner <sabre@nondot.org> | 2005-01-21 23:06:49 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-01-21 23:06:49 +0000 |
commit | 45f57b8ee3450a5c23ddaa58d8d80b12a4d50574 (patch) | |
tree | 5a1e5fed81a2949d34ad3b032366b9d2dda4b49f /lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | fb0f53f9c1693c5bec4229738c785141d8f4db1a (diff) |
Handle comparisons of gep instructions that have different typed indices
as long as they are the same size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19734 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 6312f426dd..080bc78943 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2244,9 +2244,9 @@ Instruction *InstCombiner::FoldGEPSetCC(User *GEPLHS, Value *RHS, 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 @@ Instruction *InstCombiner::FoldGEPSetCC(User *GEPLHS, Value *RHS, 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); } } |