[llvm] llvm-reduce: Fix losing operand bundles when removing arguments (PR #133410)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 28 09:39:13 PDT 2025


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133410

>From 3962ce4f55cf846c84254321aa07e3b99e9378da Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 28 Mar 2025 16:32:06 +0700
Subject: [PATCH] llvm-reduce: Fix losing operand bundles when removing
 arguments

---
 .../remove-arguments-preserve-bundles.ll      | 28 +++++++++++++++++++
 .../llvm-reduce/deltas/ReduceArguments.cpp    |  6 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/tools/llvm-reduce/remove-arguments-preserve-bundles.ll

diff --git a/llvm/test/tools/llvm-reduce/remove-arguments-preserve-bundles.ll b/llvm/test/tools/llvm-reduce/remove-arguments-preserve-bundles.ll
new file mode 100644
index 0000000000000..b370aa5d1dd3b
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/remove-arguments-preserve-bundles.ll
@@ -0,0 +1,28 @@
+; Check that when removing arguments, existing bundles 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: @convergent_callee(
+define i32 @convergent_callee(i32 %a, i32 %b) convergent {
+  ret i32 %a
+}
+
+; INTERESTING-LABEL: @convergent_callee_decl(
+declare i32 @convergent_callee_decl(i32 %a, i32 %b) convergent
+
+; INTERESTING-LABEL: @convergent_caller(
+; INTERESTING: call i32
+; INTERESTING: call i32
+
+; RESULT-LABEL: define i32 @convergent_caller()
+; RESULT: %call0 = call i32 @convergent_callee() [ "convergencectrl"(token %entry.token) ]
+; RESULT: %call1 = call i32 @convergent_callee_decl() [ "convergencectrl"(token %entry.token) ]
+define i32 @convergent_caller(i32 %x) convergent {
+  %entry.token = call token @llvm.experimental.convergence.entry()
+  %call0 = call i32 @convergent_callee(i32 %x, i32 2) [ "convergencectrl"(token %entry.token) ]
+  %call1 = call i32 @convergent_callee_decl(i32 %x, i32 2) [ "convergencectrl"(token %entry.token) ]
+  %result = add i32 %call0, %call1
+  ret i32 %result
+}
+
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
index ba8721e09b99c..a7689688fdc2b 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -61,8 +61,10 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
         }
       }
 
-      // FIXME: Losing bundles
-      CallInst *NewCI = CallInst::Create(&NewF, Args);
+      SmallVector<OperandBundleDef, 2> OpBundles;
+      CI->getOperandBundlesAsDefs(OpBundles);
+
+      CallInst *NewCI = CallInst::Create(&NewF, Args, OpBundles);
       NewCI->setCallingConv(NewF.getCallingConv());
 
       AttrBuilder CallSiteAttrs(Ctx, CI->getAttributes().getFnAttrs());



More information about the llvm-commits mailing list