[PATCH] D109103: [ISEL][BitTestBlock] omit additional bit test when default destination is unreachable

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 02:03:39 PDT 2021


hans added inline comments.


================
Comment at: llvm/lib/CodeGen/SwitchLoweringUtils.cpp:455
+  bool DefaultUnreachable =
+      isa<UnreachableInst>(SI->getDefaultDest()->getFirstNonPHIOrDbg());
   BitTestCases.emplace_back(std::move(LowBound), std::move(CmpRange),
----------------
I don't think this line is quite right.

The "default" for a bit test is not necessarily the same as the default for the SwitchInst -- it's just the block that control falls through to if all the bit tests fail, and that block could be one that handles other switch cases. (It would be better if BitTestBlock.Default was renamed to BitTestBlock.Fallthrough).

You can see how BitTestBlock.Default gets set in SelectionDAGBuilder::lowerWorkItem():

```
        // Fill in fields of the BitTestBlock.                          
        BTB->Parent = CurMBB;
        BTB->Default = Fallthrough;
```

However, that code does know whether the fallthrough block is unreachable, and already uses that to set the BitTestBlock::OmitRangeCheck. Maybe OmitRangeCheck could be renamed to UnreachableDefault, and used for both omitting the range check and skipping the last bit test? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109103



More information about the llvm-commits mailing list