[clang] [llvm] [IRBuilder] Split CreateAssumption to one with bundle and one with condition [NFC] (PR #196795)
Andreas Jonson via cfe-commits
cfe-commits at lists.llvm.org
Sun May 10 06:54:31 PDT 2026
https://github.com/andjo403 updated https://github.com/llvm/llvm-project/pull/196795
>From feb5f8fdb89e799cd723bc27b96e6ab3360487e7 Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Sun, 10 May 2026 14:46:09 +0200
Subject: [PATCH] [IRBuilder] Split CreateAssumption to one with bundle and one
with condition [NFC].
---
clang/lib/CodeGen/CGBuiltin.cpp | 2 +-
llvm/include/llvm/IR/IRBuilder.h | 13 +++++----
llvm/lib/IR/IRBuilder.cpp | 29 +++++++++----------
.../InstCombine/InstCombineCalls.cpp | 6 ++--
4 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 67de2a34f44ea..1318641159212 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3650,7 +3650,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Value *Values[] = {Value0, Value1};
OperandBundleDefT<Value *> OBD("separate_storage", Values);
- Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+ Builder.CreateAssumption({OBD});
return RValue::get(nullptr);
}
case Builtin::BI__builtin_allow_runtime_check: {
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index ca085bb4aaa11..cb0fdeaecd1cc 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -896,11 +896,11 @@ class IRBuilderBase {
/// Create an assume intrinsic call that allows the optimizer to
/// assume that the provided condition will be true.
- ///
- /// The optional argument \p OpBundles specifies operand bundles that are
- /// added to the call instruction.
- LLVM_ABI CallInst *
- CreateAssumption(Value *Cond, ArrayRef<OperandBundleDef> OpBundles = {});
+ LLVM_ABI CallInst *CreateAssumption(Value *Cond);
+
+ /// Create an assume intrinsic call that allows the optimizer to
+ /// assume that the provided operand bundles hold.
+ LLVM_ABI CallInst *CreateAssumption(ArrayRef<OperandBundleDef> OpBundles);
/// Create a llvm.experimental.noalias.scope.decl intrinsic call.
LLVM_ABI Instruction *CreateNoAliasScopeDeclaration(Value *Scope);
@@ -1025,7 +1025,8 @@ class IRBuilderBase {
ArrayRef<Type *> OverloadTypes,
ArrayRef<Value *> Args,
FMFSource FMFSource = {},
- const Twine &Name = "");
+ const Twine &Name = "",
+ ArrayRef<OperandBundleDef> OpBundles = {});
/// Create a call to intrinsic \p ID with \p RetTy and \p Args. If
/// \p FMFSource is provided, copy fast-math-flags from that instruction to
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index 706a977a5b6d5..93a2eba532ac2 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -545,16 +545,17 @@ CallInst *IRBuilderBase::CreateThreadLocalAddress(Value *Ptr) {
return CI;
}
-CallInst *
-IRBuilderBase::CreateAssumption(Value *Cond,
- ArrayRef<OperandBundleDef> OpBundles) {
+CallInst *IRBuilderBase::CreateAssumption(Value *Cond) {
assert(Cond->getType() == getInt1Ty() &&
"an assumption condition must be of type i1");
+ return CreateIntrinsic(Intrinsic::assume, /*OverloadTypes=*/{}, {Cond});
+}
- Value *Ops[] = { Cond };
- Module *M = BB->getParent()->getParent();
- Function *FnAssume = Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
- return CreateCall(FnAssume, Ops, OpBundles);
+CallInst *
+IRBuilderBase::CreateAssumption(ArrayRef<OperandBundleDef> OpBundles) {
+ Value *Args[] = {ConstantInt::getTrue(getContext())};
+ return CreateIntrinsic(Intrinsic::assume, /*OverloadTypes=*/{}, Args,
+ /*FMFSource=*/nullptr, /*Name=*/"", OpBundles);
}
Instruction *IRBuilderBase::CreateNoAliasScopeDeclaration(Value *Scope) {
@@ -930,11 +931,11 @@ Value *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS,
CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,
ArrayRef<Type *> OverloadTypes,
ArrayRef<Value *> Args,
- FMFSource FMFSource,
- const Twine &Name) {
+ FMFSource FMFSource, const Twine &Name,
+ ArrayRef<OperandBundleDef> OpBundles) {
Module *M = BB->getModule();
Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTypes);
- return createCallHelper(Fn, Args, Name, FMFSource);
+ return createCallHelper(Fn, Args, Name, FMFSource, OpBundles);
}
CallInst *IRBuilderBase::CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
@@ -1358,7 +1359,7 @@ CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
if (OffsetValue)
Vals.push_back(OffsetValue);
OperandBundleDefT<Value *> AlignOpB("align", Vals);
- return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
+ return CreateAssumption({AlignOpB});
}
CallInst *IRBuilderBase::CreateAlignmentAssumption(const DataLayout &DL,
@@ -1389,15 +1390,13 @@ CallInst *IRBuilderBase::CreateDereferenceableAssumption(Value *PtrValue,
"trying to create a deferenceable assumption on a non-pointer?");
SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
- return CreateAssumption(ConstantInt::getTrue(getContext()),
- {DereferenceableOpB});
+ return CreateAssumption({DereferenceableOpB});
}
CallInst *IRBuilderBase::CreateNonnullAssumption(Value *PtrValue) {
assert(isa<PointerType>(PtrValue->getType()) &&
"trying to create a nonnull assumption on a non-pointer?");
- return CreateAssumption(ConstantInt::getTrue(getContext()),
- OperandBundleDef("nonnull", PtrValue));
+ return CreateAssumption(OperandBundleDef("nonnull", PtrValue));
}
IRBuilderDefaultInserter::~IRBuilderDefaultInserter() = default;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index a622e0248fce8..2a8bf3ffecd6f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3604,21 +3604,19 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
break;
case Intrinsic::assume: {
Value *IIOperand = II->getArgOperand(0);
- SmallVector<OperandBundleDef, 4> OpBundles;
- II->getOperandBundlesAsDefs(OpBundles);
// Canonicalize assume(a && b) -> assume(a); assume(b);
// Note: New assumption intrinsics created here are registered by
// the InstCombineIRInserter object.
Value *A, *B;
if (match(IIOperand, m_LogicalAnd(m_Value(A), m_Value(B)))) {
- Builder.CreateAssumption(A, OpBundles);
+ Builder.CreateAssumption(A);
Builder.CreateAssumption(B);
return eraseInstFromFunction(*II);
}
// assume(!(a || b)) -> assume(!a); assume(!b);
if (match(IIOperand, m_Not(m_LogicalOr(m_Value(A), m_Value(B))))) {
- Builder.CreateAssumption(Builder.CreateNot(A), OpBundles);
+ Builder.CreateAssumption(Builder.CreateNot(A));
Builder.CreateAssumption(Builder.CreateNot(B));
return eraseInstFromFunction(*II);
}
More information about the cfe-commits
mailing list