[all-commits] [llvm/llvm-project] 583fa4: [InstCombine] Extend fcmp+select folding to minnum...
Alexey Bader via All-commits
all-commits at lists.llvm.org
Tue Oct 15 11:05:38 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 583fa4f5b7c1d114d44cfe8c357e1c12a0d0544e
https://github.com/llvm/llvm-project/commit/583fa4f5b7c1d114d44cfe8c357e1c12a0d0544e
Author: Alexey Bader <alexey.bader at intel.com>
Date: 2024-10-15 (Tue, 15 Oct 2024)
Changed paths:
M llvm/include/llvm/IR/PatternMatch.h
M llvm/lib/Analysis/IVDescriptors.cpp
M llvm/lib/Analysis/ValueTracking.cpp
M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
M llvm/test/Transforms/InstCombine/clamp-to-minmax.ll
M llvm/test/Transforms/InstCombine/minmax-fold.ll
M llvm/test/Transforms/InstCombine/minmax-fp.ll
M llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
M llvm/unittests/IR/PatternMatch.cpp
Log Message:
-----------
[InstCombine] Extend fcmp+select folding to minnum/maxnum intrinsics (#112088)
Today, InstCombine can fold fcmp+select patterns to minnum/maxnum
intrinsics when the nnan and nsz flags are set. The ordering of the
operands in both the fcmp and select instructions is important for the
folding to occur.
maxnum patterns:
1. (a op b) ? a : b -> maxnum(a, b), where op is one of {ogt, oge}
2. (a op b) ? b : a -> maxnum(a, b), where op is one of {ule, ult}
The second pattern is supposed to make the order of the operands in the
select instruction irrelevant. However, the pattern matching code uses
the CmpInst::getInversePredicate method to invert the comparison
predicate. This method doesn't take into account the fast-math flags,
which can lead missing the folding opportunity.
The patch extends the pattern matching code to handle unordered fcmp
instructions. This allows the folding to occur even when the select
instruction has the operands in the inverse order.
New maxnum patterns:
1. (a op b) ? a : b -> maxnum(a, b), where op is one of {ugt, uge}
2. (a op b) ? b : a -> maxnum(a, b), where op is one of {ole, olt}
The same changes are applied to the minnum intrinsic.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list