[PATCH] D108408: [InstCombine] Transform X == 0 ? 0 : X * Y --> X * freeze(Y).

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 11:09:04 PDT 2021


lebedev.ri added a comment.

In D108408#2958735 <https://reviews.llvm.org/D108408#2958735>, @fzhinkin wrote:

> In D108408#2958323 <https://reviews.llvm.org/D108408#2958323>, @lebedev.ri wrote:
>
>> 1. what's wrong with vectors?
>
> There's nothing wrong, I'll support it, thanks!
>
>> 2. can't we preserve no-wrap flags?
>
> Definitely.
>
>> 3. for vectors, what if some element is not zero but undef? (see ` Constant::mergeUndefsWith()`)
>
> Not sure that I fully understand the issue.
> If `%a` in the snippet below contains some undefs then the select may choose either `0` or  `%m` depending on particular value of `a` (which could be `0` for undef elements).
> Probably `%a` should be frozen to ensure that both `icmp` and `mul` will see the same `a`'s value, but (if I understood it correctly) absence of `freeze` does not compromise the correctness.
>
>   define <2 x i4> @src(<2 x i4> %a, <2 x i4> %b) {
>     %c = icmp eq <2 x i4> %a, zeroinitializer
>     %m = mul <2 x i4> %a, %b
>     %r = select <2 x i1> %c, <2 x i4> zeroinitializer, <2 x i4> %m
>     ret <2 x i4> %r
>   }
>
> Or you meant that the code could be folded even if `icmp`'s RHS is not only the all-zeros vector, but a constant-vector containing some undefs?

I mean that if in either zero constant vector, a particular element is undef, then in the other constant vector, the same element can be anything:
https://alive2.llvm.org/ce/z/-gt253
https://alive2.llvm.org/ce/z/3PAU3E

So i think you want `if(!match(Constant::mergeUndefsWith(TrueVal, CondVal.getOperand(1)), m_Zero)) return;`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108408



More information about the llvm-commits mailing list