[llvm] [IRBUilder] Split CreateAssumption to one with bundle and one with condition [NFC] (PR #196795)

via llvm-commits llvm-commits at lists.llvm.org
Sun May 10 05:48:58 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Andreas Jonson (andjo403)

<details>
<summary>Changes</summary>

as it is not possible to combine bundles and conditions from https://github.com/llvm/llvm-project/pull/160460 reflect that in CreateAssumption

---
Full diff: https://github.com/llvm/llvm-project/pull/196795.diff


3 Files Affected:

- (modified) llvm/include/llvm/IR/IRBuilder.h (+7-6) 
- (modified) llvm/lib/IR/IRBuilder.cpp (+14-15) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+2-4) 


``````````diff
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index ca085bb4aaa11..7188826857f7f 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 are holds.
+  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);
     }

``````````

</details>


https://github.com/llvm/llvm-project/pull/196795


More information about the llvm-commits mailing list