[ARM] Fix FixConst for ARMCodeGenPrepare
Part of FixConsts wrongly assumes either a 8- or 16-bit constant
which can result in the wrong constants being generated during
promotion.
Differential Revision: https://reviews.llvm.org/D52032
llvm-svn: 342140
diff --git a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
index bc33e65..28bb482 100644
--- a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
+++ b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
@@ -271,13 +271,6 @@
return true;
}
- // Otherwise, if an instruction is using a negative immediate we will need
- // to fix it up during the promotion.
- for (auto &Op : I->operands()) {
- if (auto *Const = dyn_cast<ConstantInt>(Op))
- if (Const->isNegative())
- return false;
- }
return false;
}
@@ -370,19 +363,9 @@
};
auto FixConst = [&](ConstantInt *Const, Instruction *I) {
- Constant *NewConst = nullptr;
- if (isSafeOverflow(I)) {
- NewConst = (Const->isNegative()) ?
- ConstantExpr::getSExt(Const, ExtTy) :
- ConstantExpr::getZExt(Const, ExtTy);
- } else {
- uint64_t NewVal = *Const->getValue().getRawData();
- if (Const->getType() == Type::getInt16Ty(Ctx))
- NewVal &= 0xFFFF;
- else
- NewVal &= 0xFF;
- NewConst = ConstantInt::get(ExtTy, NewVal);
- }
+ Constant *NewConst = isSafeOverflow(I) && Const->isNegative() ?
+ ConstantExpr::getSExt(Const, ExtTy) :
+ ConstantExpr::getZExt(Const, ExtTy);
I->replaceUsesOfWith(Const, NewConst);
};