[cgp] Defer lazy domtree usage to last possible point

This is a compile time optimization for d9e93e8e5. Not sure this matters or not, but why not do it just in case.

This does involve querying TLI with a potentially invalid addressing mode for the using instruction, but since we don't actually pass the using instruction to the TLI callback, that should be fine.
This commit is contained in:
Philip Reames 2021-03-04 10:18:10 -08:00
parent da1e37a8b0
commit 6af94d22f7
1 changed files with 5 additions and 2 deletions

View File

@ -3912,12 +3912,15 @@ bool AddressingModeMatcher::matchScaledValue(Value *ScaleReg, int64_t Scale,
Instruction *IVInc = IVStep->first;
APInt Step = IVStep->second;
APInt Offset = Step * AddrMode.Scale;
if (Offset.isSignedIntN(64) && getDTFn().dominates(IVInc, MemoryInst)) {
if (Offset.isSignedIntN(64)) {
TestAddrMode.InBounds = false;
TestAddrMode.ScaledReg = IVInc;
TestAddrMode.BaseOffs -= Offset.getLimitedValue();
// If this addressing mode is legal, commit it..
if (TLI.isLegalAddressingMode(DL, TestAddrMode, AccessTy, AddrSpace)) {
// (Note that we defer the (expensive) domtree base legality check
// to the very last possible point.)
if (TLI.isLegalAddressingMode(DL, TestAddrMode, AccessTy, AddrSpace) &&
getDTFn().dominates(IVInc, MemoryInst)) {
AddrModeInsts.push_back(cast<Instruction>(IVInc));
AddrMode = TestAddrMode;
return true;