[PATCH] D69720: [InstCombine] propagate fast-math-flags (FMF) to select when inverting fcmp+select

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 10:09:03 PDT 2019


spatel created this revision.
spatel added reviewers: arsenm, efriedma, hfinkel, reames.
Herald added subscribers: dexonsmith, hiraditya, mehdi_amini, wdng, mcrosier.
Herald added a project: LLVM.
spatel edited the summary of this revision.
spatel edited the summary of this revision.

As noted by the FIXME comment, this is not correct based on our current FMF semantics. We should be propagating FMF from the final value in a sequence (in this case the 'select'). So the behavior even without this patch is wrong, but we did not allow FMF on 'select' until recently.

But if we do the correct thing right now in this patch, we'll inevitably introduce regressions because we have not wired up FMF propagation for 'phi' and 'select' in other passes (like SimplifyCFG) or other places in InstCombine. I'm not seeing a better incremental way to make progress.

That said, the potential extra damage over the existing wrong behavior from this patch is very limited. AFAIK, the only way to have different FMF on IR in the same function is if we have LTO inlined IR from 2 modules that were compiled using different fast-math settings.

As seen in the tests, we may actually see some improvements with this patch because adding the FMF to the 'select' allows matching to min/max intrinsics that were previously missed (in the common case, the 'fcmp' and 'select' should have identical FMF to begin with).

Next steps in the transition:

1. Make similar changes in instcombine as needed.
2. Enable phi-to-select FMF propagation in SimplifyCFG.
3. Remove dependencies on fcmp with FMF.
4. Deprecate FMF on fcmp.


https://reviews.llvm.org/D69720

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/clamp-to-minmax.ll
  llvm/test/Transforms/InstCombine/minmax-fold.ll
  llvm/test/Transforms/InstCombine/minmax-fp.ll
  llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69720.227467.patch
Type: text/x-patch
Size: 19693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191101/f8bde1de/attachment.bin>


More information about the llvm-commits mailing list