[all-commits] [llvm/llvm-project] 99108c: [SimplifyCFG] Update FoldBranchToCommonDest to be ...

Juneyoung Lee via All-commits all-commits at lists.llvm.org
Sun Mar 7 08:38:32 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 99108c791de0285ee726a10e8274772b18cee73c
      https://github.com/llvm/llvm-project/commit/99108c791de0285ee726a10e8274772b18cee73c
  Author: Juneyoung Lee <aqjune at gmail.com>
  Date:   2021-03-08 (Mon, 08 Mar 2021)

  Changed paths:
    M llvm/include/llvm/IR/IRBuilder.h
    M llvm/include/llvm/Transforms/Utils/Local.h
    M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    M llvm/test/Transforms/PGOProfile/chr.ll
    M llvm/test/Transforms/SimplifyCFG/ARM/branch-fold-threshold.ll
    M llvm/test/Transforms/SimplifyCFG/annotations.ll
    M llvm/test/Transforms/SimplifyCFG/common-dest-folding.ll
    M llvm/test/Transforms/SimplifyCFG/fold-branch-to-common-dest.ll
    M llvm/test/Transforms/SimplifyCFG/fold-debug-location.ll
    M llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
    M llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll

  Log Message:
  -----------
  [SimplifyCFG] Update FoldBranchToCommonDest to be poison-safe

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.

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. `PoisonSafe` flag is set to false in this case because enabling it has a nontrivial impact in performance because SCEV is more conservative with select form and InductiveRangeCheckElimination isn't aware of select form of and/or i1.

Reviewed By: nikic

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




More information about the All-commits mailing list