diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-07-18 23:07:33 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-07-18 23:07:33 +0000 | 
| commit | 247aef884c78dc5b92a4aa73d2629fc12ba009ae (patch) | |
| tree | 3560741a2e72cb7ddc5ac913c361e135e1d5d99d | |
| parent | b35912e4212006d3e8b382b4295106fac6a9e5ac (diff) | |
| download | bcm5719-llvm-247aef884c78dc5b92a4aa73d2629fc12ba009ae.tar.gz bcm5719-llvm-247aef884c78dc5b92a4aa73d2629fc12ba009ae.zip | |
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
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 15 | 
1 files changed, 11 insertions, 4 deletions
| diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index e2ef04ea1df..b838289e59c 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -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);        }      } | 

