[PATCH] D96663: [InstCombine] Fold icmp (select c, const, arg), null if arg has nonnullattr

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 23 22:15:57 PST 2021


aqjune added a comment.

Instead of adding two transformations, I tweaked InstCombinerImpl::foldICmpInstWithConstantNotInt so it fires if icmp is comparing to null and select's true/false operands are either a constant or nonnullattr argument.
It allows:

    %.0.i = select i1 %2, i8* null, i8* %x
    %4 = icmp ne i8* %.0.i, null
    call void @llvm.assume(i1 %4)
    ret i8* %.0.1
  =>
    %.0.i = select i1 %2, i8* null, i8* %x
    %temp = xor i1 %2, 1
    call void @llvm.assume(i1 %temp)
    ret i8* %.0.1
  =>  
    ...
    ret i8* %x

BTW, fixing SimplifyCFG to replace phi operand with null doesn't work for the Rust example because phi is already folded into select before inlining. It roughly looks like this: https://godbolt.org/z/c38qon


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96663



More information about the llvm-commits mailing list