[PATCH] D95026: [SimplifyCFG] Update FoldBranchToCommonDest to be poison-safe

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 20 00:16:07 PST 2021


aqjune created this revision.
aqjune added reviewers: nikic, fhahn, lebedev.ri.
Herald added subscribers: dexonsmith, wenlei, javed.absar, hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch makes FoldBranchToCommonDest merge branch conditions into `select i1` rather than `and/or i1` when it is called by SimplifyCFG.
It is known that merging conditions into and/or is poison-unsafe, and this is towards making things *more* correct by removing possible miscompilations.
Currently, InstCombine simply consumes these selects into and/or of i1 (which is also unsafe), so the visible effect would be very small. The unsafe select -> and/or transformation will be removed in the future.
There has been efforts for updating optimizations to support the select form as well, and they are linked to D93065 <https://reviews.llvm.org/D93065>.

The safe transformation is fired when it is called by SimplifyCFG only. This is done by setting the new `PoisonSafe` argument as true.
Another place that calls FoldBranchToCommonDest is LoopSimplify. I think this will have a nontrivial impact since SCEV is more conservative in this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95026

Files:
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/PatternMatch.h
  llvm/include/llvm/Transforms/Utils/Local.h
  llvm/lib/Target/BPF/BPFAdjustOpt.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/LoopSimplify/pr26682.ll
  llvm/test/Transforms/PGOProfile/chr.ll
  llvm/test/Transforms/SimplifyCFG/ARM/branch-fold-threshold.ll
  llvm/test/Transforms/SimplifyCFG/annotations.ll
  llvm/test/Transforms/SimplifyCFG/basictest.ll
  llvm/test/Transforms/SimplifyCFG/common-dest-folding.ll
  llvm/test/Transforms/SimplifyCFG/fold-branch-to-common-dest.ll
  llvm/test/Transforms/SimplifyCFG/fold-debug-location.ll
  llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
  llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
  llvm/test/Transforms/SimplifyCFG/switch_create.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95026.317792.patch
Type: text/x-patch
Size: 31387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210120/1176fe3e/attachment.bin>


More information about the llvm-commits mailing list