[llvm] [InstCombine] Fix for folding `select` into floating point binary operators. (PR #83200)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 17:52:44 PDT 2024


arsenm wrote:

> Seems all we need is this change:
> 
> ```
> diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
> index aaf4ece3249a..c8d9b4ee446e 100644
> --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
> +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
> @@ -551,7 +551,7 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
>      // This makes the transformation incorrect since the original program would
>      // have preserved the exact NaN bit-pattern.
>      // Avoid the folding if the false value might be a NaN.
> -    if (isa<FPMathOperator>(&SI) &&
> +    if (isa<FPMathOperator>(&SI) && !TVI->getFastMathFlags().noNaNs()  &&
>          !computeKnownFPClass(FalseVal, FMF, fcNan, &SI).isKnownNeverNaN())
>        return nullptr;
> ```
> 
> I had been lost in that logic at first, then I've found that it's the `TVI` that has the `-f(no-)honor-nans` flag right (with its default value for `-ffast-math` set accordingly).

Testcase for this? 

https://github.com/llvm/llvm-project/pull/83200


More information about the llvm-commits mailing list