[PATCH] D129204: [X86][NFCI] Remove target-specific branch optimisation that's handled in BranchFolding

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 00:51:11 PDT 2022


asb added a comment.

In D129204#3668750 <https://reviews.llvm.org/D129204#3668750>, @RKSimon wrote:

> In D129204#3668746 <https://reviews.llvm.org/D129204#3668746>, @pengfei wrote:
>
>> There seems a test for it: https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/X86/brcond.ll#L39
>> Maybe it has become dead code. LGTM.
>
> @asb please can you confirm if the tests fail if the OptimizeBlock variant of the code is disabled as well?

Weirdly that particular test in brcond.ll doesn't fail, but if disabling the code that implements this transform in OptimizeBlock:

  --- a/llvm/lib/CodeGen/BranchFolding.cpp
  +++ b/llvm/lib/CodeGen/BranchFolding.cpp
  @@ -1452,17 +1452,17 @@ ReoptimizeBlock:
       // If the prior block branches here on true and somewhere else on false, and
       // if the branch condition is reversible, reverse the branch to create a
       // fall-through.
  -    if (PriorTBB == MBB) {
  -      SmallVector<MachineOperand, 4> NewPriorCond(PriorCond);
  -      if (!TII->reverseBranchCondition(NewPriorCond)) {
  -        DebugLoc dl = getBranchDebugLoc(PrevBB);
  -        TII->removeBranch(PrevBB);
  -        TII->insertBranch(PrevBB, PriorFBB, nullptr, NewPriorCond, dl);
  -        MadeChange = true;
  -        ++NumBranchOpts;
  -        goto ReoptimizeBlock;
  -      }
  -    }
  +//  if (PriorTBB == MBB) {
  +//    SmallVector<MachineOperand, 4> NewPriorCond(PriorCond);
  +//    if (!TII->reverseBranchCondition(NewPriorCond)) {
  +//      DebugLoc dl = getBranchDebugLoc(PrevBB);
  +//      TII->removeBranch(PrevBB);
  +//      TII->insertBranch(PrevBB, PriorFBB, nullptr, NewPriorCond, dl);
  +//      MadeChange = true;
  +//      ++NumBranchOpts;
  +//      goto ReoptimizeBlock;
  +//    }
  +//  }

Then the following X86 tests fails:

  Failed Tests (8):
    LLVM :: CodeGen/X86/2010-09-17-SideEffectsInChain.ll
    LLVM :: CodeGen/X86/atomic-flags.ll
    LLVM :: CodeGen/X86/fp-une-cmp.ll
    LLVM :: CodeGen/X86/ins_subreg_coalesce-3.ll
    LLVM :: CodeGen/X86/reverse_branches.ll
    LLVM :: CodeGen/X86/speculative-load-hardening.ll
    LLVM :: CodeGen/X86/stack-protector-3.ll
    LLVM :: CodeGen/X86/switch.ll


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

https://reviews.llvm.org/D129204



More information about the llvm-commits mailing list