[PATCH] D125755: [AggressiveInstcombine] Conditionally fold saturated fptosi to llvm.fptosi.sat
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 17 03:03:06 PDT 2022
dmgreen created this revision.
dmgreen added reviewers: spatel, RKSimon, efriedma, craig.topper, nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
dmgreen requested review of this revision.
Herald added a project: LLVM.
This adds a fold for aggressive instcombine that converts smin(smax(fptosi(x))) into a llvm.fptosi.sat, providing that the saturation constants are correct and the cost of the llvm.fptosi.sat is lower.
Unfortunately, a llvm.fptosi.sat cannot always be converted back to a smin/smax/fptosi. The llvm.fptosi.sat intrinsic is more defined that the original, which produces poison if the original fptosi was out of range. The llvm.fptosi.sat will saturate any value, so needs to be expanded to a fptosi(fpmin(fpmax(x))), which can be worse for codegeneration depending on the target.
So this is an RFC change that is conditional on the backend reporting that the llvm.fptosi.sat is cheaper that the original smin+smax+fptost. This is a change to the way that AggressiveInstrcombine has worked in the past. Instead of just being a canonicalization pass, that canonicalization can be dependant on the target in certain specific cases. This concept can also be useful in other cases such as the table base cttz from D113291 <https://reviews.llvm.org/D113291> and possibly funnel shifts? (although I know the
details there less).
https://reviews.llvm.org/D125755
Files:
llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
llvm/test/Transforms/AggressiveInstCombine/AArch64/fptosisat.ll
llvm/test/Transforms/AggressiveInstCombine/ARM/fptosisat.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125755.429977.patch
Type: text/x-patch
Size: 30480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220517/1ce2903f/attachment.bin>
More information about the llvm-commits
mailing list