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.
Paths
| Differential D146349
[InstCombine] Make `FoldOpIntoSelect` handle non-constants and use condition to deduce constants. ClosedPublic Authored by goldstein.w.n on Mar 17 2023, 7:05 PM.
Details Summary 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
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. This revision now requires changes to proceed.Mar 21 2023, 2:04 AM Comment Actions
Done and agreed. Updated version only uses the information from the condition goldstein.w.n added a parent revision: D147900: [ValueTracking] Use `select` condition to help determine if `select` is non-zero.Apr 9 2023, 5:21 PM goldstein.w.n removed a parent revision: D146347: [InstCombine] Improve transforms for `(mul X, Y)` -> `(shl X, log2(Y)`. 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
Thats what happens in: D146350, do you want me to merge the two? 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). goldstein.w.n removed a parent revision: D147900: [ValueTracking] Use `select` condition to help determine if `select` is non-zero.Apr 12 2023, 4:06 PM goldstein.w.n marked an inline comment as done. This revision is now accepted and ready to land.Apr 13 2023, 12:29 AM This revision was landed with ongoing or failed builds.Apr 14 2023, 11:14 AM Closed by commit rG82f082761383: [InstCombine] Make `FoldOpIntoSelect` handle non-constants and use condition to… (authored by goldstein.w.n). · Explain Why This revision was automatically updated to reflect the committed changes. 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: Comment Actions
Revision Contents
Diff 506259 llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
|
Why was this factored out into a separate function? Doesn't really seem to simplify things.