[all-commits] [llvm/llvm-project] 540f68: [SimplifyCFG] Don't use a mask for lookup tables g...

DaPorkchop_ via All-commits all-commits at lists.llvm.org
Sat Jun 8 06:32:55 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 540f68c44f4813c2c16f92ccbba5a15e8ff87c85
      https://github.com/llvm/llvm-project/commit/540f68c44f4813c2c16f92ccbba5a15e8ff87c85
  Author: DaPorkchop_ <daporkchop at daporkchop.net>
  Date:   2024-06-08 (Sat, 08 Jun 2024)

  Changed paths:
    M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    M llvm/test/Transforms/SimplifyCFG/RISCV/switch-of-powers-of-two.ll
    M llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
    A llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table_big.ll

  Log Message:
  -----------
  [SimplifyCFG] Don't use a mask for lookup tables generated from switches with an unreachable default case (#94468)

When transforming a switch with holes into a lookup table, we currently
use a mask to check if the current index is handled by the switch or if
it is a hole. If it is a hole, we skip loading from the lookup table.
Normally, if the switch's default case is unreachable this has no
impact, as the mask test gets optimized away by subsequent passes.
However, if the switch is large enough that the number of lookup table
entries exceeds the target's register width, we won't be able to fit all
the cases into a mask and the switch won't get transformed into a lookup
table. If we know that the switch's default case is unreachable, we know
that the mask is unnecessary and can skip constructing it entirely,
which allows us to transform the switch into a lookup table.

[Example](https://godbolt.org/z/7x7qfx8M1)

In the future, it might be interesting to consider allowing lookup table
masks to be more than one register large (e.g. using a constant array of
bit flags, similar to `std::bitset`).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list