Make the fold use the information present in the condition for deducing constants i.e:
%c = icmp eq i8 %x, 10 %s = select i1 %c, i8 3, i8 2 %r = mul i8 %x, %s
If we fold the mul into the select, on the true side we insert 10 for %x in the mul.
Differential D146349
[InstCombine] Make `FoldOpIntoSelect` handle non-constants and use condition to deduce constants. goldstein.w.n on Mar 17 2023, 7:05 PM. Authored by
Details Make the fold use the information present in the condition for deducing constants i.e: %c = icmp eq i8 %x, 10 %s = select i1 %c, i8 3, i8 2 %r = mul i8 %x, %s If we fold the mul into the select, on the true side we insert 10 for %x in the mul.
Diff Detail
Unit Tests Event TimelineComment Actions Can you please rebase over https://github.com/llvm/llvm-project/commit/d0de2c51c9a9fc0fedb97ee98f61ce08cb34972b? I hope that will clarify what the actual change here is, because making foldOperationIntoSelectOperand() fallible doesn't make a whole lot of sense. Comment Actions Done and agreed. Updated version only uses the information from the condition Comment Actions This should also relax the requirement on at least one caller so that the change becomes testable. Or maybe you can use the one in InstCombineCalls to test this, I think one of the multi-argument intrinsics should work.
Comment Actions That patch does more than we need for this. It would be enough to relax any of the existing calls (or use the intrinsic one if it works). Comment Actions Sorry, I missed something in this patch as well. This transform isn't valid for undef constants: https://alive2.llvm.org/ce/z/4JjGKv We should guard it against isGuaranteedNotToBeUndefOrPoison. Comment Actions Because its constant elements can we just do C->containsUndefOrPoisonElement()? Edit2: |
Why was this factored out into a separate function? Doesn't really seem to simplify things.