Skip to content
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
4 changes: 3 additions & 1 deletion llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,8 @@ assumptions, such as that a :ref:`parameter attribute <paramattrs>` or a
location. Operand bundles enable assumptions that are either hard or impossible
to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`.

Assumes with operand bundles must have ``i1 true`` as the condition operand.

An assume operand bundle has the form:

::
Expand Down Expand Up @@ -3045,7 +3047,7 @@ allows the optimizer to assume that at location of call to

.. code-block:: llvm

call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(ptr %val)]
call void @llvm.assume(i1 true) ["cold"(), "nonnull"(ptr %val)]

allows the optimizer to assume that the :ref:`llvm.assume <int_assume>`
call location is cold and that ``%val`` may not be null.
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5675,6 +5675,11 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
default:
break;
case Intrinsic::assume: {
if (Call.hasOperandBundles()) {
auto *Cond = dyn_cast<ConstantInt>(Call.getArgOperand(0));
Check(Cond && Cond->isOne(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could use m_One(), but not sure if it would be really more compact

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this, but we currently don't use PatternMatch at all inside the Verifier, so I stuck with the existing style.

"assume with operand bundles must have i1 true condition", Call);
}
for (auto &Elem : Call.bundle_op_infos()) {
unsigned ArgCount = Elem.End - Elem.Begin;
// Separate storage assumptions are special insofar as they're the only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

define void @fn1() {
; CHECK-LABEL: define void @fn1() {
; CHECK-NEXT: call void @llvm.assume(i1 false) [ "align"(ptr @global, i64 1) ]
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr @global, i64 1) ]
; CHECK-NEXT: ret void
;
call void @llvm.assume(i1 false) [ "align"(ptr @global, i64 1) ]
call void @llvm.assume(i1 true) [ "align"(ptr @global, i64 1) ]
ret void
}

Expand Down
16 changes: 8 additions & 8 deletions llvm/test/Transforms/InstCombine/assume.ll
Original file line number Diff line number Diff line change
Expand Up @@ -498,24 +498,24 @@ not_taken:
define i1 @nonnull3B(ptr %a, i1 %control) {
; CHECK-LABEL: @nonnull3B(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[A:%.*]], align 8
; CHECK-NEXT: br i1 [[CONTROL:%.*]], label [[TAKEN:%.*]], label [[NOT_TAKEN:%.*]]
; CHECK: taken:
; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[A:%.*]], align 8
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[LOAD]], null
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]]) [ "nonnull"(ptr [[LOAD]]) ]
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[LOAD]]) ]
; CHECK-NEXT: ret i1 true
; CHECK: not_taken:
; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[LOAD]]) ]
; CHECK-NEXT: ret i1 false
;
entry:
%load = load ptr, ptr %a
%cmp = icmp ne ptr %load, null
br i1 %control, label %taken, label %not_taken
taken:
call void @llvm.assume(i1 %cmp) ["nonnull"(ptr %load)]
call void @llvm.assume(i1 true) ["nonnull"(ptr %load)]
ret i1 %cmp
not_taken:
call void @llvm.assume(i1 %cmp) ["nonnull"(ptr %load)]
call void @llvm.assume(i1 true) ["nonnull"(ptr %load)]
ret i1 %control
}

Expand Down Expand Up @@ -544,7 +544,7 @@ taken:
br label %exit
exit:
; FIXME: this shouldn't be dropped because it is still dominated by the new position of %load
call void @llvm.assume(i1 %cmp) ["nonnull"(ptr %load)]
call void @llvm.assume(i1 %cmp)
ret i1 %cmp2
not_taken:
call void @llvm.assume(i1 %cmp)
Expand Down Expand Up @@ -575,7 +575,7 @@ taken:
exit:
ret i1 %cmp2
not_taken:
call void @llvm.assume(i1 %cmp) ["nonnull"(ptr %load)]
call void @llvm.assume(i1 %cmp)
ret i1 %control
}

Expand Down
4 changes: 3 additions & 1 deletion llvm/test/Verifier/assume-bundles.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

declare void @llvm.assume(i1)

define void @func(ptr %P, i32 %P1, ptr %P2, ptr %P3) {
define void @func(ptr %P, i32 %P1, ptr %P2, ptr %P3, i1 %cond) {
; CHECK: tags must be valid attribute names
; CHECK: "adazdazd"
call void @llvm.assume(i1 true) ["adazdazd"()]
Expand Down Expand Up @@ -32,5 +32,7 @@ define void @func(ptr %P, i32 %P1, ptr %P2, ptr %P3) {
call void @llvm.assume(i1 true) ["separate_storage"(ptr %P, i32 123)]
; CHECK: dereferenceable assumptions should have 2 arguments
call void @llvm.assume(i1 true) ["align"(ptr %P, i32 4), "dereferenceable"(ptr %P)]
; CHECK: assume with operand bundles must have i1 true condition
call void @llvm.assume(i1 %cond) ["nonnull"(ptr %P)]
ret void
}
6 changes: 3 additions & 3 deletions mlir/test/Target/LLVMIR/Import/intrinsic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,12 @@ define void @assume(i1 %true) {
}

; CHECK-LABEL: @assume_with_opbundles
; CHECK-SAME: %[[TRUE:[a-zA-Z0-9]+]]
; CHECK-SAME: %[[PTR:[a-zA-Z0-9]+]]
define void @assume_with_opbundles(i1 %true, ptr %p) {
define void @assume_with_opbundles(ptr %p) {
; CHECK: %[[TRUE:.+]] = llvm.mlir.constant(true) : i1
; CHECK: %[[ALIGN:.+]] = llvm.mlir.constant(8 : i32) : i32
; CHECK: llvm.intr.assume %[[TRUE]] ["align"(%[[PTR]], %[[ALIGN]] : !llvm.ptr, i32)] : i1
call void @llvm.assume(i1 %true) ["align"(ptr %p, i32 8)]
call void @llvm.assume(i1 true) ["align"(ptr %p, i32 8)]
ret void
}

Expand Down
7 changes: 4 additions & 3 deletions mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,11 @@ llvm.func @assume_without_opbundles(%cond: i1) {
}

// CHECK-LABEL: @assume_with_opbundles
llvm.func @assume_with_opbundles(%cond: i1, %p: !llvm.ptr) {
llvm.func @assume_with_opbundles(%p: !llvm.ptr) {
%true = llvm.mlir.constant(true) : i1
%0 = llvm.mlir.constant(8 : i32) : i32
// CHECK: call void @llvm.assume(i1 %{{.+}}) [ "align"(ptr %{{.+}}, i32 8) ]
llvm.intr.assume %cond ["align"(%p, %0 : !llvm.ptr, i32)] : i1
// CHECK: call void @llvm.assume(i1 true) [ "align"(ptr %{{.+}}, i32 8) ]
llvm.intr.assume %true ["align"(%p, %0 : !llvm.ptr, i32)] : i1
llvm.return
}

Expand Down