Debian Codegraph @

external/llvm/releases/14.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 a7317169c80681f9128c22f5f071e206b7617c28 Mon Sep 17 00:00:00 2001
20 From: Artem Gindinson <[email protected]>
21 Date: Wed, 23 Aug 2023 15:49:30 +0200
22 Subject: [PATCH] [InstCombine] Check for NaN before folding `select` for FP
23 operators
24
25 ---
26 llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 12 ++++++++++++
27 1 file changed, 12 insertions(+)
28
29 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
30 index 881b00f2a..9cdde7433 100644
31 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
32 +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
33 @@ -455,6 +455,12 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
34 }
35
36 if (OpToFold) {
37 + FastMathFlags FMF;
38 + if (isa<FPMathOperator>(&SI)) {
39 + FMF = SI.getFastMathFlags();
40 + if (!FMF.noNaNs())
41 + return nullptr;
42 + }
43 Constant *C = ConstantExpr::getBinOpIdentity(TVI->getOpcode(),
44 TVI->getType(), true);
45 Value *OOp = TVI->getOperand(2-OpToFold);
46 @@ -487,6 +493,12 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
47 }
48
49 if (OpToFold) {
50 + FastMathFlags FMF;
51 + if (isa<FPMathOperator>(&SI)) {
52 + FMF = SI.getFastMathFlags();
53 + if (!FMF.noNaNs())
54 + return nullptr;
55 + }
56 Constant *C = ConstantExpr::getBinOpIdentity(FVI->getOpcode(),
57 FVI->getType(), true);
58 Value *OOp = FVI->getOperand(2-OpToFold);