Debian Codegraph @

external/llvm/releases/16.0.0/patches_external/check-for-NaN-before-folding-select-for-FP.patch

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2023 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 /*========================== begin_copyright_notice ============================
10
11 Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12 See https://llvm.org/LICENSE.txt for license information.
13 SPDX-License-Identifier: Apache-2.0 with LLVM-exception
14
15 ============================= end_copyright_notice ===========================*/
16
17 # TODO: Once upstreamed, update with LLORG revision & adjust per community review
18
19 From 492a1c879f338c3f12ef4d2f619ca2c8f2467da8 Mon Sep 17 00:00:00 2001
20 From: Artem Gindinson <[email protected]>
21 Date: Wed, 23 Aug 2023 15:41:51 +0200
22 Subject: [PATCH] [InstCombine] Check for NaN before folding `select` for FP
23 operators
24
25 ---
26 llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 6 +++++-
27 1 file changed, 5 insertions(+), 1 deletion(-)
28
29 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
30 index e7d8208f9..341d8fc49 100644
31 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
32 +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
33 @@ -484,8 +484,12 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
34 // instructions have different flags and add tests to ensure the
35 // behaviour is correct.
36 FastMathFlags FMF;
37 - if (isa<FPMathOperator>(&SI))
38 + if (isa<FPMathOperator>(&SI)) {
39 FMF = SI.getFastMathFlags();
40 + // Avoid folding on NaN inputs
41 + if (!FMF.noNaNs())
42 + return nullptr;
43 + }
44 Constant *C = ConstantExpr::getBinOpIdentity(
45 TVI->getOpcode(), TVI->getType(), true, FMF.noSignedZeros());
46 Value *OOp = TVI->getOperand(2 - OpToFold);
47