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

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 1 15:55:32 PDT 2021


nickdesaulniers created this revision.
nickdesaulniers added reviewers: hans, craig.topper, lebedev.ri.
Herald added subscribers: pengfei, hiraditya.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Otherwise we end up with an extra conditional jump, following by an
unconditional jump off the end of a function. ie.

bb.0:

  BT32rr ..
  JCC_1 %bb.4 ...

bb.1:

  BT32rr ..
  JCC_1 %bb.2 ...
  JMP_1 %bb.3

bb.2:

  ...

bb.3.unreachable:
bb.4:

  ...

Should be equivalent to:
bb.0:

  BT32rr ..
  JCC_1 %bb.4 ...
  JMP_1 %bb.2

bb.1:
bb.2:

  ...

bb.3.unreachable:
bb.4:

  ...

This can occur since at the higher level IR (Instruction) SwitchInsts
are required to have BBs for default destinations, even when it can be
deduced that such BBs are unreachable.

For most programs, this isn't an issue, just wasted instructions since the
unreachable has been statically proven.

The x86_64 Linux kernel when built with CONFIG_LTO_CLANG_THIN=y fails to
boot though once D106056 <https://reviews.llvm.org/D106056> is re-applied.  D106056 <https://reviews.llvm.org/D106056> makes it more likely
that correlation-propagation (CVP) can deduce that the default case of
SwitchInsts are unreachable. The x86_64 kernel uses a binary post
processor called objtool, which emits this warning:

vmlinux.o: warning: objtool: cfg80211_edmg_chandef_valid()+0x169: can't
find jump dest instruction at .text.cfg80211_edmg_chandef_valid+0x17b

I haven't debugged precisely why this causes a failure at boot time, but
fixing this very obvious jump off the end of the function fixes the
warning and boot problem.

Link: https://bugs.llvm.org/show_bug.cgi?id=50080
Fixes: https://github.com/ClangBuiltLinux/linux/issues/679
Fixes: https://github.com/ClangBuiltLinux/linux/issues/1440


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109103

Files:
  llvm/include/llvm/CodeGen/SwitchLoweringUtils.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  llvm/lib/CodeGen/SwitchLoweringUtils.cpp
  llvm/test/CodeGen/X86/SwitchLowering.ll
  llvm/test/CodeGen/X86/switch-bit-test-unreachable-default.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109103.370093.patch
Type: text/x-patch
Size: 6397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210901/2468e0de/attachment.bin>


More information about the llvm-commits mailing list