mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 07:06:38 +00:00
llvm-reduce: Fix losing fast math flags when removing arguments (#133408)
This commit is contained in:
parent
1b86867ab3
commit
688df34634
26
llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll
Normal file
26
llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll
Normal file
@ -0,0 +1,26 @@
|
||||
; Check that when removing arguments, existing fast math flags are preserved
|
||||
|
||||
; 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
|
||||
; RUN: FileCheck --check-prefixes=RESULT %s < %t
|
||||
|
||||
; INTERESTING-LABEL: @math_callee(
|
||||
define float @math_callee(float %a, float %b) {
|
||||
%add = fadd float %a, %b
|
||||
ret float %add
|
||||
}
|
||||
|
||||
; INTERESTING-LABEL: @math_callee_decl(
|
||||
declare float @math_callee_decl(float %a, float %b)
|
||||
|
||||
; INTERESTING-LABEL: @math_caller(
|
||||
; INTERESTING: call
|
||||
; INTERESTING: call
|
||||
|
||||
; RESULT: %call0 = call nnan nsz float @math_callee()
|
||||
; RESULT: %call1 = call ninf float @math_callee_decl()
|
||||
define float @math_caller(float %x) {
|
||||
%call0 = call nnan nsz float @math_callee(float %x, float 2.0)
|
||||
%call1 = call ninf float @math_callee_decl(float %x, float 2.0)
|
||||
%result = fadd float %call0, %call1
|
||||
ret float %result
|
||||
}
|
@ -16,8 +16,10 @@
|
||||
#include "Utils.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/FMF.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/Intrinsics.h"
|
||||
#include "llvm/IR/Operator.h"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
@ -59,7 +61,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Losing bundles, fast math flags and metadata
|
||||
// FIXME: Losing bundles and metadata
|
||||
CallInst *NewCI = CallInst::Create(&NewF, Args);
|
||||
NewCI->setCallingConv(NewF.getCallingConv());
|
||||
|
||||
@ -73,6 +75,9 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
|
||||
++ArgI, ++AttrIdx)
|
||||
NewCI->addParamAttrs(AttrIdx, ArgAttrs[AttrIdx]);
|
||||
|
||||
if (auto *FPOp = dyn_cast<FPMathOperator>(NewCI))
|
||||
cast<Instruction>(FPOp)->setFastMathFlags(CI->getFastMathFlags());
|
||||
|
||||
if (!CI->use_empty())
|
||||
CI->replaceAllUsesWith(NewCI);
|
||||
ReplaceInstWithInst(CI, NewCI);
|
||||
|
Loading…
x
Reference in New Issue
Block a user