Skip to content

llvm-reduce: Fix losing fast math flags when removing arguments #133408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 6 additions & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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());

Expand All @@ -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);
Expand Down
Loading