[PATCH] D70502: Broaden the definition of a "widenable branch"

Artur Pilipenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 10:23:25 PST 2019


apilipenko accepted this revision.
apilipenko added inline comments.
This revision is now accepted and ready to land.


================
Comment at: llvm/lib/Transforms/Utils/GuardUtils.cpp:73
 
-  Instruction *WCAnd = cast<Instruction>(WidenableBR->getCondition());
-  // Condition is only guaranteed to dominate branch
-  WCAnd->moveBefore(WidenableBR);
-  Value *OldCond = WCAnd->getOperand(0);
-  IRBuilder<> B(WCAnd);
-  WCAnd->setOperand(0, B.CreateAnd(NewCond, OldCond));
-
+  if (match(WidenableBR->getCondition(),
+            m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
----------------
reames wrote:
> ebrevnov wrote:
> > Would it be better to use parseWidenableBranch instead of repeating its logic here.
> Can't.  I wish we could and tried to find a way, but we need to modify the existing instructions to preserve the "one use" requirement on the widenable condition to be able to determine it's a trivially widenable branch.  
Yeah, a naive approach here would be to replace `wc` with `(newc && wc)`. It handles both trivial and non-trivial widenable branches. The only problem is it makes a pattern which is not recognized by parseWidenableBranch.
```
br (c && wc), ... - widenable branch
=>
br (c && (newc && wc)), ... - not (obviously) widenable anymore
```

Can you add a comment that we do it this way because we need to preserve the structure `(c && wc)` which is recognized by parseWidenableBranch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70502





More information about the llvm-commits mailing list