[PATCH] D106041: [WIP][SimpleLoopUnswitch] Re-fix introduction of UB when hoisted condition may be undef or poison

Hyeongyu Kim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 3 05:16:39 PDT 2021


hyeongyukim added a subscriber: aqjune.
hyeongyukim added a comment.

While analyzing the cause of performance regression, I found that `freeze(icmp(..))` is interrupting `SimplifyCFG.`
And most of them will be solved by pushing freeze to `icmp`'s operands. (Make `freeze(icmp(Op0, Op1))` to `icmp(freeze(Op0), freeze(Op1))`)

  if (InsertFreeze) {
    auto Cond = SI->getCondition();
    if (!isGuaranteedNotToBeUndefOrPoison(Cond, &AC, BI, &DT)) {
      if (ICmpInst* I = dyn_cast<ICmpInst>(Cond)) {
        Value* Op0 = I->getOperand(0);
        Value* Op1 = I->getOperand(1);
  
        auto FreezeOperand = [&](Value* Op) {
          if (isGuaranteedNotToBePoison(Op, &AC, BI, &DT)) 
            return;
  
          auto *FrozenOp = new FreezeInst(Op, Op->getName() + ".fr");
          FrozenOp->insertBefore(I);
          Op = FrozenOp;
          return;
        };
  
        FreezeOperand(Op0);
        FreezeOperand(Op1);
      }
      else
        SI->setCondition(new FreezeInst(Cond, Cond->getName() + ".fr", SI));
    }
  }

Actually, performance regression was significantly reduced when the above code was added.
Before I push freeze to `icmp`'s operands, 104 assembly diffs were found while compiling the LLVM testsuite.
But after I apply the above code, 104 assembly diffs were reduced to 37. (Which means performance regression was reduced)

But I'm not sure it's the right approach to treat icmp separately inside the LU. 
Can you check if it's okay to add these codes? @aqjune


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106041/new/

https://reviews.llvm.org/D106041



More information about the llvm-commits mailing list