[CGP] Avoid repeatedly building DominatorTree causing long compile-time (NFC)
authorTeresa Johnson <tejohnson@google.com>
Wed, 6 Mar 2019 14:57:40 +0000 (14:57 +0000)
committerTeresa Johnson <tejohnson@google.com>
Wed, 6 Mar 2019 14:57:40 +0000 (14:57 +0000)
commitb1daf0aef67d4998aef2bbfd7709bc0ee0e89923
tree74ab9e1a47857994c2fd7e3581962ffb8035850a
parent6b622ebea01b3ece8b8e475f15c5ce16a4cdc9f8
[CGP] Avoid repeatedly building DominatorTree causing long compile-time (NFC)

Summary:
In r354298 a DominatorTree construction was added via new function
combineToUSubWithOverflow, which was subsequently restructured into
replaceMathCmpWithIntrinsic in r354689. We are hitting a very long
compile time due to this repeated construction, once per math cmp in
the function.

We shouldn't need to build the DominatorTree more than once per
function, except when a transformation invalidates it. There is already
a boolean flag that is returned from these methods indicating whether
the DT has been modified. We can simply build the DT once per
Function walk in CodeGenPrepare::runOnFunction, since any time a change
is made we break out of the Function walk and restart it.

I modified the code so that both replaceMathCmpWithIntrinsic as well as
mergeSExts (which was also building a DT) use the DT constructed by the
run method.

From -mllvm -time-passes:
Before this patch: CodeGen Prepare user time is 328s
With this patch: CodeGen Prepare user time is 21s

Reviewers: spatel

Subscribers: jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 355512
llvm/lib/CodeGen/CodeGenPrepare.cpp