mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-28 07:17:32 +00:00
Implement InstCombine/GEPIdxCanon.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15024 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2700,7 +2700,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
Value *Op = GEP.getOperand(i);
|
Value *Op = GEP.getOperand(i);
|
||||||
if (Op->getType()->getPrimitiveSize() > TD->getPointerSize())
|
if (Op->getType()->getPrimitiveSize() > TD->getPointerSize())
|
||||||
if (Constant *C = dyn_cast<Constant>(Op)) {
|
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;
|
MadeChange = true;
|
||||||
} else {
|
} else {
|
||||||
Op = InsertNewInstBefore(new CastInst(Op, TD->getIntPtrType(),
|
Op = InsertNewInstBefore(new CastInst(Op, TD->getIntPtrType(),
|
||||||
@@ -2708,6 +2709,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
GEP.setOperand(i, Op);
|
GEP.setOperand(i, Op);
|
||||||
MadeChange = true;
|
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;
|
if (MadeChange) return &GEP;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user