mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-21 08:17:40 +00:00
Fix for incorrect address sinking in the presence of potential overflows.
In some cases it is possible for CGP to attempt to reuse a base address from another basic block. In those cases we have to be sure that all the address math was either done at the same bit width, or that none of it overflowed before it was extended. Patch by Louis Gerbarg <lgg@apple.com> rdar://16307442 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204833 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2438,7 +2438,14 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
|
||||
cast<IntegerType>(V->getType())->getBitWidth()) {
|
||||
V = Builder.CreateTrunc(V, IntPtrTy, "sunkaddr");
|
||||
} else {
|
||||
V = Builder.CreateSExt(V, IntPtrTy, "sunkaddr");
|
||||
// It is only safe to sign extend the BaseReg if we know that the math
|
||||
// required to create it did not overflow before we extend it. Since
|
||||
// the original IR value was tossed in favor of a constant back when
|
||||
// the AddrMode was created we need to bail out gracefully if widths
|
||||
// do not match instead of extending it.
|
||||
if (Result != AddrMode.BaseReg)
|
||||
cast<Instruction>(Result)->eraseFromParent();
|
||||
return false;
|
||||
}
|
||||
if (AddrMode.Scale != 1)
|
||||
V = Builder.CreateMul(V, ConstantInt::get(IntPtrTy, AddrMode.Scale),
|
||||
|
||||
Reference in New Issue
Block a user