aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-07-18 23:07:33 +0000
committerChris Lattner <sabre@nondot.org>2005-07-18 23:07:33 +0000
commit7911f036266fc9cd63534b9bb225523d021bab7c (patch)
tree10f5f66d916f07c43ec6d042af1192b0111d36ce /lib/Transforms
parentf4d32726e622c740b4befc803e604903eb1349df (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index e2ef04ea1d..b838289e59 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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);
}
}