Skip to content

llvm-reduce: Do not delete convergencectrl in operand-bundles #133858

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; Check that invalid reductions aren't introduced by deleting
; convergencectrl bundles in convergent functions
;
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operand-bundles --test FileCheck --test-arg --check-prefixes=CHECK,INTERESTING --test-arg %s --test-arg --input-file %s -o %t
; RUN: FileCheck --check-prefixes=CHECK,RESULT %s < %t

; CHECK-LABEL: define float @convergentctrl_one_interesting(
; INTERESTING: %interesting = call float @convergent.extern.func(
; RESULT: %entry.token = call token @llvm.experimental.convergence.entry()
; RESULT: %interesting = call float @convergent.extern.func(float %x) [ "convergencectrl"(token %entry.token) ]
; RESULT: %boring = call float @convergent.extern.func(float %x) [ "convergencectrl"(token %entry.token) ]
define float @convergentctrl_one_interesting(float %x, float %y) #0 {
%entry.token = call token @llvm.experimental.convergence.entry()
%interesting = call float @convergent.extern.func(float %x) [ "convergencectrl"(token %entry.token) ]
%boring = call float @convergent.extern.func(float %x) [ "convergencectrl"(token %entry.token) ]
%add = fadd float %interesting, %boring
ret float %add
}

; In theory we could remove the bundle here, since all convergencectrl
; in the function will be removed.

; CHECK-LABEL: define float @convergentctrl_can_remove_all(
; RESULT: %entry.token = call token @llvm.experimental.convergence.entry()
; RESULT: %val = call float @convergent.extern.func(float %x) [ "convergencectrl"(token %entry.token) ]
define float @convergentctrl_can_remove_all(float %x, float %y) #0 {
%entry.token = call token @llvm.experimental.convergence.entry()
%val = call float @convergent.extern.func(float %x) [ "convergencectrl"(token %entry.token) ]
ret float %val
}

declare float @convergent.extern.func(float) #0
declare token @llvm.experimental.convergence.entry() #1

attributes #0 = { convergent }
attributes #1 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
14 changes: 12 additions & 2 deletions llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ using namespace llvm;

namespace {

/// Return true if stripping the bundle from a call will result in invalid IR.
static bool shouldKeepBundleTag(uint32_t BundleTagID) {
// In convergent functions using convergencectrl bundles, all convergent calls
// must use the convergence bundles so don't try to remove them.
return BundleTagID == LLVMContext::OB_convergencectrl;
}

/// Given ChunksToKeep, produce a map of calls and indexes of operand bundles
/// to be preserved for each call.
class OperandBundleRemapper : public InstVisitor<OperandBundleRemapper> {
Expand All @@ -53,9 +60,12 @@ class OperandBundleRemapper : public InstVisitor<OperandBundleRemapper> {
OperandBundlesToKeepIndexes.reserve(Call.getNumOperandBundles());

// Enumerate every operand bundle on this call.
for (unsigned BundleIndex : seq(Call.getNumOperandBundles()))
if (O.shouldKeep()) // Should we keep this one?
for (unsigned BundleIndex : seq(Call.getNumOperandBundles())) {
if (shouldKeepBundleTag(
Call.getOperandBundleAt(BundleIndex).getTagID()) ||
O.shouldKeep()) // Should we keep this one?
OperandBundlesToKeepIndexes.emplace_back(BundleIndex);
}
}
};

Expand Down