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

This commit is contained in:
Matt Arsenault 2025-03-28 23:28:03 +07:00 committed by GitHub
parent 688df34634
commit 115a77df9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -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}

View File

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