mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-21 19:32:16 +00:00
Update InstCombine worklist after instruction transform is complete.
When updating the worklist for InstCombine, the Add/AddUsersToWorklist functions may access the instruction(s) being added, for debug output for example. If the instructions aren't yet added to the basic block, this can result in a crash. Finish the instruction transformation before adjusting the worklist instead. rdar://10238555 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141203 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
591c1c6754
commit
30c1ff234d
@ -2009,21 +2009,18 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
|||||||
++NumCombined;
|
++NumCombined;
|
||||||
// Should we replace the old instruction with a new one?
|
// Should we replace the old instruction with a new one?
|
||||||
if (Result != I) {
|
if (Result != I) {
|
||||||
DEBUG(errs() << "IC: Old = " << *I << '\n'
|
|
||||||
<< " New = " << *Result << '\n');
|
|
||||||
|
|
||||||
if (!I->getDebugLoc().isUnknown())
|
if (!I->getDebugLoc().isUnknown())
|
||||||
Result->setDebugLoc(I->getDebugLoc());
|
Result->setDebugLoc(I->getDebugLoc());
|
||||||
// Everything uses the new instruction now.
|
// Everything uses the new instruction now.
|
||||||
I->replaceAllUsesWith(Result);
|
I->replaceAllUsesWith(Result);
|
||||||
|
|
||||||
// Push the new instruction and any users onto the worklist.
|
// Move the name to the new instruction.
|
||||||
Worklist.Add(Result);
|
|
||||||
Worklist.AddUsersToWorkList(*Result);
|
|
||||||
|
|
||||||
// Move the name to the new instruction first.
|
|
||||||
Result->takeName(I);
|
Result->takeName(I);
|
||||||
|
|
||||||
|
DEBUG(errs() << "IC: Old = " << *I << '\n'
|
||||||
|
<< " New = " << *Result << '\n');
|
||||||
|
|
||||||
|
|
||||||
// Insert the new instruction into the basic block...
|
// Insert the new instruction into the basic block...
|
||||||
BasicBlock *InstParent = I->getParent();
|
BasicBlock *InstParent = I->getParent();
|
||||||
BasicBlock::iterator InsertPos = I;
|
BasicBlock::iterator InsertPos = I;
|
||||||
@ -2035,6 +2032,10 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
|||||||
InstParent->getInstList().insert(InsertPos, Result);
|
InstParent->getInstList().insert(InsertPos, Result);
|
||||||
|
|
||||||
EraseInstFromFunction(*I);
|
EraseInstFromFunction(*I);
|
||||||
|
|
||||||
|
// Push the new instruction and any users onto the worklist.
|
||||||
|
Worklist.Add(Result);
|
||||||
|
Worklist.AddUsersToWorkList(*Result);
|
||||||
} else {
|
} else {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
DEBUG(errs() << "IC: Mod = " << OrigI << '\n'
|
DEBUG(errs() << "IC: Mod = " << OrigI << '\n'
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
define i32 @main(i32 %argc) nounwind ssp {
|
define i32 @main(i32 %argc) nounwind ssp {
|
||||||
entry:
|
entry:
|
||||||
%tmp3151 = trunc i32 %argc to i8
|
%tmp3151 = trunc i32 %argc to i8
|
||||||
; CHECK: %tmp3162 = shl i8 %tmp3151, 5
|
; CHECK: %0 = shl i8 %tmp3151, 5
|
||||||
; CHECK: and i8 %tmp3162, 64
|
; CHECK: and i8 %0, 64
|
||||||
; CHECK-NOT: shl
|
; CHECK-NOT: shl
|
||||||
; CHECK-NOT: shr
|
; CHECK-NOT: shr
|
||||||
%tmp3161 = or i8 %tmp3151, -17
|
%tmp3161 = or i8 %tmp3151, -17
|
||||||
|
Loading…
x
Reference in New Issue
Block a user