This patch add a function foldSelectToFabs, and do more combine for
fneg-of-fabs.
With 'nsz'
fold (X < +/-0.0) ? X : -X or (X <= +/-0.0) ? X : -X to -fabs(x) fold (X > +/-0.0) ? X : -X or (X >= +/-0.0) ? X : -X to -fabs(x)
Paths
| Differential D123830
[InstCombine] Complete folding of fneg-of-fabs ClosedPublic Authored by Chenbing.Zheng on Apr 14 2022, 7:40 PM.
Details Summary This patch add a function foldSelectToFabs, and do more combine for With 'nsz' fold (X < +/-0.0) ? X : -X or (X <= +/-0.0) ? X : -X to -fabs(x) fold (X > +/-0.0) ? X : -X or (X >= +/-0.0) ? X : -X to -fabs(x)
Diff Detail
Event TimelineComment Actions This doesn't solve the root problem. If we start with the existing code in the test that is changing, it will not become fneg(fabs) like we want? We should extend the code under InstCombinerImpl::visitSelectInst() to match "nabs" patterns. Search for: "// Canonicalize select with fcmp to fabs()." Chenbing.Zheng retitled this revision from [InstCombine] Optimize folding of fneg-of-fabs to [InstCombine] Complete folding of fneg-of-fabs. Comment Actionsaddress comments
Comment Actions
Yes, this looks nicer. See inline for some small improvements.
This revision is now accepted and ready to land.Apr 24 2022, 7:27 AM This revision was landed with ongoing or failed builds.Apr 24 2022, 6:54 PM Closed by commit rG5805cfb90127: [InstCombine] Complete folding of fneg-of-fabs (authored by Chenbing.Zheng). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 424807 llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/fneg-fabs.ll
llvm/test/Transforms/InstCombine/fneg.ll
|
Swap should be a bool parameter, and the caller can use "for (bool Swap : {false, true} )".
Or we can move the FNeg part of the transform into this function and avoid the parameter completely?