[InstCombine] Prevent InstCombine from triggering an extra iteration if something changed in the initial Worklist creation

Summary:
If the Worklist build causes an IR change this change flag currently factors into the flag for running another iteration of the iteration loop. But only changes during processing should trigger another loop.

This patch captures the worklist creation change flag into the outside the loop flag currently used for DbgDeclares and only sends that flag up to the caller. Rerunning the loop only depends on IC.run() now.

This uses the debug output of InstCombine to determine if one or two iterations run. I couldn't think of a better way to detect it since the second spurious iteration shoudn't make any visible changes. Just wasted computation.

I can do a pre-commit of the test case with the CHECK-NOT as a CHECK if this is an ok way to check this.

This is a subset of D31678 as I'm still not sure how to verify the analysis behavior for that.

Reviewers: davide, majnemer, spatel, chandlerc

Reviewed By: davide

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D32453

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302982 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2017-05-13 06:56:04 +00:00
parent b3213cf9db
commit f671e9e87b
2 changed files with 14 additions and 5 deletions

View File

@ -3141,7 +3141,7 @@ combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist,
// Lower dbg.declare intrinsics otherwise their value may be clobbered
// by instcombiner.
bool DbgDeclaresChanged = LowerDbgDeclare(F);
bool MadeIRChange = LowerDbgDeclare(F);
// Iterate while there is work to do.
int Iteration = 0;
@ -3150,18 +3150,17 @@ combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist,
DEBUG(dbgs() << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
<< F.getName() << "\n");
bool Changed = prepareICWorklistFromFunction(F, DL, &TLI, Worklist);
MadeIRChange |= prepareICWorklistFromFunction(F, DL, &TLI, Worklist);
InstCombiner IC(Worklist, &Builder, F.optForMinSize(), ExpensiveCombines,
AA, AC, TLI, DT, DL, LI);
IC.MaxArraySizeForCombine = MaxArraySize;
Changed |= IC.run();
if (!Changed)
if (!IC.run())
break;
}
return DbgDeclaresChanged || Iteration > 1;
return MadeIRChange || Iteration > 1;
}
PreservedAnalyses InstCombinePass::run(Function &F,

View File

@ -0,0 +1,10 @@
; RUN: opt < %s -instcombine -S -debug 2>&1 | FileCheck %s
; REQUIRES: asserts
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
define i32 @a() nounwind readnone {
entry:
ret i32 zext (i1 icmp eq (i32 0, i32 ptrtoint (i32 ()* @a to i32)) to i32)
}
; CHECK: INSTCOMBINE ITERATION #1
; CHECK-NOT: INSTCOMBINE ITERATION #2