Skip to content

llvm-reduce: Fix losing metadata when removing arguments #133409

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
7 changes: 5 additions & 2 deletions llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ declare float @math_callee_decl(float %a, float %b)
; INTERESTING: call
; INTERESTING: call

; RESULT: %call0 = call nnan nsz float @math_callee()
; RESULT: %call0 = call nnan nsz float @math_callee(), !fpmath !0
; 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)
%call0 = call nnan nsz float @math_callee(float %x, float 2.0), !fpmath !0
%call1 = call ninf float @math_callee_decl(float %x, float 2.0)
%result = fadd float %call0, %call1
ret float %result
}

; RESULT: !0 = !{float 2.000000e+00}
!0 = !{float 2.0}
4 changes: 3 additions & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
}
}

// FIXME: Losing bundles and metadata
// FIXME: Losing bundles
CallInst *NewCI = CallInst::Create(&NewF, Args);
NewCI->setCallingConv(NewF.getCallingConv());

Expand All @@ -78,6 +78,8 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
if (auto *FPOp = dyn_cast<FPMathOperator>(NewCI))
cast<Instruction>(FPOp)->setFastMathFlags(CI->getFastMathFlags());

NewCI->copyMetadata(*CI);

if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
ReplaceInstWithInst(CI, NewCI);
Expand Down
Loading