Skip to content

Commit d9c03f0

Browse files
committed
llvm-reduce: Fix losing fast math flags when removing arguments
1 parent a783fcb commit d9c03f0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; Check that when removing arguments, existing fast math flags are preserved
2+
3+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments --test FileCheck --test-arg --check-prefixes=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
4+
; RUN: FileCheck --check-prefixes=RESULT %s < %t
5+
6+
; INTERESTING-LABEL: @math_callee(
7+
define float @math_callee(float %a, float %b) {
8+
%add = fadd float %a, %b
9+
ret float %add
10+
}
11+
12+
; INTERESTING-LABEL: @math_callee_decl(
13+
declare float @math_callee_decl(float %a, float %b)
14+
15+
; INTERESTING-LABEL: @math_caller(
16+
; INTERESTING: call
17+
; INTERESTING: call
18+
19+
; RESULT: %call0 = call nnan nsz float @math_callee()
20+
; RESULT: %call1 = call ninf float @math_callee_decl()
21+
define float @math_caller(float %x) {
22+
%call0 = call nnan nsz float @math_callee(float %x, float 2.0)
23+
%call1 = call ninf float @math_callee_decl(float %x, float 2.0)
24+
%result = fadd float %call0, %call1
25+
ret float %result
26+
}

llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
#include "Utils.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/IR/Constants.h"
19+
#include "llvm/IR/FMF.h"
1920
#include "llvm/IR/Instructions.h"
2021
#include "llvm/IR/Intrinsics.h"
22+
#include "llvm/IR/Operator.h"
2123
#include <set>
2224
#include <vector>
2325

@@ -59,7 +61,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
5961
}
6062
}
6163

62-
// FIXME: Losing bundles, fast math flags and metadata
64+
// FIXME: Losing bundles and metadata
6365
CallInst *NewCI = CallInst::Create(&NewF, Args);
6466
NewCI->setCallingConv(NewF.getCallingConv());
6567

@@ -73,6 +75,9 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
7375
++ArgI, ++AttrIdx)
7476
NewCI->addParamAttrs(AttrIdx, ArgAttrs[AttrIdx]);
7577

78+
if (auto *FPOp = dyn_cast<FPMathOperator>(NewCI))
79+
cast<Instruction>(FPOp)->setFastMathFlags(CI->getFastMathFlags());
80+
7681
if (!CI->use_empty())
7782
CI->replaceAllUsesWith(NewCI);
7883
ReplaceInstWithInst(CI, NewCI);

0 commit comments

Comments
 (0)