When transforming &A[i] < &A[j] -> i < j, make sure to perform the comparison

as a signed compare.  This patch may fix PR597, but is correct in any case.

llvm-svn: 22465
This commit is contained in:
Chris Lattner 2005-07-18 23:07:33 +00:00
parent b35912e421
commit 247aef884c
1 changed files with 11 additions and 4 deletions

View File

@ -2367,10 +2367,17 @@ Instruction *InstCombiner::FoldGEPSetCC(User *GEPLHS, Value *RHS,
else if (NumDifferences == 1) {
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);
// Convert the operands to signed values to make sure to perform a
// signed comparison.
const Type *NewTy = LHSV->getType()->getSignedVersion();
if (LHSV->getType() != NewTy)
LHSV = InsertNewInstBefore(new CastInst(LHSV, NewTy,
LHSV->getName()), I);
if (RHSV->getType() != NewTy)
RHSV = InsertNewInstBefore(new CastInst(RHSV, NewTy,
RHSV->getName()), I);
return new SetCondInst(Cond, LHSV, RHSV);
}
}