[PATCH] D119839: [SimplifyCFG] Propagating case value when turning switch range into icmp

weiwei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 15 07:11:24 PST 2022


wwei added a comment.

In D119839#3322795 <https://reviews.llvm.org/D119839#3322795>, @lebedev.ri wrote:

> It doesn't look like something SimplifyCFG should be dealing with.

@lebedev.ri The reason is that after switch range is converted to icmp, the original case value no longer exists in the IR, and there is no chance for other pass to eliminate this comparison instruction. Look at the IR after simplifycfg:

  define i64 @demo(i64 %x) {
  entry:
    %switch = icmp ult i64 %x, 1
    %0 = icmp eq i64 %x, 100     ; %x == 1?  no pass can get this result!
    %. = select i1 %0, i64 200, i64 10
    %common.ret.op = select i1 %switch, i64 0, i64 %.
    ret i64 %common.ret.op
  }

So It's impossible to remove `%0 = icmp eq i64 %x, 100`. Maybe simplifycfg has the responsibility to do constant propagation if switch to icmp transformation is performed.
I can't find other solutions at the moment, do you have better suggestions or deas?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119839



More information about the llvm-commits mailing list