https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/133409
None >From 828f5b07b5ba4523148cd7d2c5b400d271500923 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <matthew.arsena...@amd.com> Date: Fri, 28 Mar 2025 16:29:29 +0700 Subject: [PATCH] llvm-reduce: Fix losing metadata when removing arguments --- .../tools/llvm-reduce/remove-arguments-preserve-fmf.ll | 7 +++++-- llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll b/llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll index 2ceb3e717200b..4c78920ede44a 100644 --- a/llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll +++ b/llvm/test/tools/llvm-reduce/remove-arguments-preserve-fmf.ll @@ -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} diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp index aea4d1dc186c4..11c3ab027f61f 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -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); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits