diff options
author | Chris Lattner <sabre@nondot.org> | 2004-07-20 01:48:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-07-20 01:48:15 +0000 |
commit | 67769e5efa23bd46695e1397c730da096ea08bb8 (patch) | |
tree | e4660a4402c3b92866bf8f427cf781f317af6e98 /lib/Transforms | |
parent | 247d62c77bc2efd14fb52b223808af7021807da9 (diff) |
Implement InstCombine/GEPIdxCanon.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15024 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 6b993750a3..27ba7ab163 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2700,7 +2700,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { Value *Op = GEP.getOperand(i); if (Op->getType()->getPrimitiveSize() > TD->getPointerSize()) if (Constant *C = dyn_cast<Constant>(Op)) { - GEP.setOperand(i, ConstantExpr::getCast(C, TD->getIntPtrType())); + GEP.setOperand(i, ConstantExpr::getCast(C, + TD->getIntPtrType()->getSignedVersion())); MadeChange = true; } else { Op = InsertNewInstBefore(new CastInst(Op, TD->getIntPtrType(), @@ -2708,6 +2709,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { GEP.setOperand(i, Op); MadeChange = true; } + + // If this is a constant idx, make sure to canonicalize it to be a signed + // operand, otherwise CSE and other optimizations are pessimized. + if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(Op)) { + GEP.setOperand(i, ConstantExpr::getCast(CUI, + CUI->getType()->getSignedVersion())); + MadeChange = true; + } } if (MadeChange) return &GEP; |