[PATCH] D95296: [SimplifyCFG] Don't create switch from two equality comparisons (WIP)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 23 13:18:32 PST 2021


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, xbolva00.
Herald added subscribers: wenlei, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

SimplifyCFG currently forms a switch from an `X == C1 || X == C2` style comparison. This negatively interferes with other optimizations, primarily because many important loop optimizations like rotation and vectorizations do not handle switches (https://bugs.llvm.org/show_bug.cgi?id=44461, https://bugs.llvm.org/show_bug.cgi?id=48844). At the same time forming a two-case switch with a common target is unlikely to be beneficial for further optimization or target lowering.

This patch changes the heuristic to require at least three cases in the switch, rather than only two. This is just a prototype patch to get some initial feedback on whether the approach is sound (I would need to adjust tests to preserve intent). An alternative suggested by @xbolva00 is to instead delay this fold until late in the pipeline. Would that be a better approach?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95296

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/PGOProfile/chr.ll
  llvm/test/Transforms/PhaseOrdering/X86/pr48844-br-to-switch-vectorization.ll
  llvm/test/Transforms/PhaseOrdering/pr44461-br-to-switch-rotate.ll
  llvm/test/Transforms/SimplifyCFG/DeadSetCC.ll
  llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
  llvm/test/Transforms/SimplifyCFG/switch_create.ll
  llvm/test/Transforms/SimplifyCFG/switch_msan.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95296.318786.patch
Type: text/x-patch
Size: 32779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210123/8175bd7d/attachment.bin>


More information about the llvm-commits mailing list