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 | 44d0b9502a0ba0925e6680ff414ba8b97c60a6b7 (patch) | |
tree | aa6849c11e00195a1e5b5fbc43069c83b5c53577 /llvm | |
parent | 9492af43c46735b60440ea82245266058a6015d0 (diff) | |
download | bcm5719-llvm-44d0b9502a0ba0925e6680ff414ba8b97c60a6b7.tar.gz bcm5719-llvm-44d0b9502a0ba0925e6680ff414ba8b97c60a6b7.zip |
Implement InstCombine/GEPIdxCanon.ll
llvm-svn: 15024
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 6b993750a3f..27ba7ab1633 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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; |