Skip to content

Commit 429582d

Browse files
committed
[mlir][llvm] Add is constant intrinsic.
The revision adds LLVM's is constant intrinsic. Depends on D150643 Reviewed By: Dinistro Differential Revision: https://reviews.llvm.org/D150660
1 parent ddb27b1 commit 429582d

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,17 @@ def LLVM_USubWithOverflowOp : LLVM_ArithWithOverflowOp<"usub.with.overflow">;
262262
def LLVM_SMulWithOverflowOp : LLVM_ArithWithOverflowOp<"smul.with.overflow">;
263263
def LLVM_UMulWithOverflowOp : LLVM_ArithWithOverflowOp<"umul.with.overflow">;
264264

265+
//
266+
// Optimization hint intrinsics.
267+
//
268+
265269
def LLVM_AssumeOp
266270
: LLVM_ZeroResultIntrOp<"assume", []>, Arguments<(ins I1:$cond)>;
267271

268-
//
269-
// Expect intrinsics.
270-
//
272+
def LLVM_IsConstantOp : LLVM_IntrOp<"is.constant", [], [0], [Pure], 1> {
273+
let arguments = (ins LLVM_Type:$val);
274+
let results = (outs I1:$res);
275+
}
271276

272277
def LLVM_ExpectOp
273278
: LLVM_OneResultIntrOp<"expect", [], [0],

mlir/test/Target/LLVMIR/Import/intrinsic.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ define void @assume(i1 %true) {
467467
ret void
468468
}
469469

470+
; CHECK-LABEL: @is_constant
471+
; CHECK-SAME: %[[VAL:[a-zA-Z0-9]+]]
472+
define void @is_constant(i32 %0) {
473+
; CHECK: "llvm.intr.is.constant"(%[[VAL]]) : (i32) -> i1
474+
%2 = call i1 @llvm.is.constant.i32(i32 %0)
475+
ret void
476+
}
477+
470478
; CHECK-LABEL: @expect
471479
; CHECK-SAME: %[[VAL:[a-zA-Z0-9]+]]
472480
define void @expect(i32 %0) {
@@ -792,6 +800,7 @@ declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32)
792800
declare { <8 x i32>, <8 x i1> } @llvm.smul.with.overflow.v8i32(<8 x i32>, <8 x i32>)
793801
declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
794802
declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>)
803+
declare i1 @llvm.is.constant.i32(i32)
795804
declare i32 @llvm.expect.i32(i32, i32)
796805
declare i16 @llvm.expect.with.probability.i16(i16, i16, double immarg)
797806
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)

mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ llvm.func @umul_with_overflow_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>,
466466
llvm.return
467467
}
468468

469+
// CHECK-LABEL: @is_constant
470+
llvm.func @is_constant(%arg0: i32) {
471+
// CHECK: call i1 @llvm.is.constant.i32(i32 %{{.*}})
472+
%0 = "llvm.intr.is.constant"(%arg0) : (i32) -> i1
473+
llvm.return
474+
}
475+
469476
// CHECK-LABEL: @expect
470477
llvm.func @expect(%arg0: i32) {
471478
%0 = llvm.mlir.constant(42 : i32) : i32
@@ -830,6 +837,7 @@ llvm.func @lifetime(%p: !llvm.ptr) {
830837
// CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.usub.with.overflow.v8i32(<8 x i32>, <8 x i32>)
831838
// CHECK-DAG: declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
832839
// CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>)
840+
// CHECK-DAG: declare i1 @llvm.is.constant.i32(i32)
833841
// CHECK-DAG: declare i32 @llvm.expect.i32(i32, i32)
834842
// CHECK-DAG: declare i16 @llvm.expect.with.probability.i16(i16, i16, double immarg)
835843
// CHECK-DAG: declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)

0 commit comments

Comments
 (0)