[llvm] [InstCombine] Fix for folding `select` into floating point binary operators. (PR #83200)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 29 22:11:01 PST 2024
================
@@ -1,8 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
-define float @select_fadd(i1 %cond, float %A, float %B) {
-; CHECK-LABEL: @select_fadd(
+define float @select_maybe_nan_fadd(i1 %cond, float %A, float %B) {
+; CHECK-LABEL: @select_maybe_nan_fadd(
+; CHECK-NEXT: [[C:%.*]] = fadd float [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[D:%.*]] = select i1 [[COND:%.*]], float [[C]], float [[A]]
+; CHECK-NEXT: ret float [[D]]
+;
+ %C = fadd float %A, %B
+ %D = select i1 %cond, float %C, float %A
+ ret float %D
+}
+
+define float @select_fpclass_fadd(i1 %cond, float nofpclass(nan) %A, float %B) {
----------------
michele-scandale wrote:
@arsenm This is the test I added to cover the case where the fast-math flags on the `select` are not present, but we still perform the optimization because we can figure out that `%A` cannot be a NaN due the `nofpclass(nan)` attribute on the function parameter.
https://github.com/llvm/llvm-project/pull/83200
More information about the llvm-commits
mailing list