[SimplifyCFG] Handle two equal cases in switch to select
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 4 Apr 2021 08:49:59 +0000 (10:49 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 4 Apr 2021 15:27:28 +0000 (17:27 +0200)
commit9bad7de9a3fb844f1ca2965f35d0c2a3d1e11775
tree2b1c5f16bc92661bba6e3a32d780a6937b739455
parent7ca168dd5adabcc01e957fb8486ddf2e22dd37d7
[SimplifyCFG] Handle two equal cases in switch to select

When converting a switch with two cases and a default into a
select, also handle the denegerate case where two cases have the
same value.

Generate this case directly as

  %or = or i1 %cmp1, %cmp2
  %res = select i1 %or, i32 %val, i32 %default

rather than

  %sel1 = select i1 %cmp1, i32 %val, i32 %default
  %res = select i1 %cmp2, i32 %val, i32 %sel1

as InstCombine is going to canonicalize to the former anyway.
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/PhaseOrdering/partialord-ule.ll
llvm/test/Transforms/SimplifyCFG/switch-to-select-two-case.ll