[Mlir-commits] [mlir] 429582d - [mlir][llvm] Add is constant intrinsic.
Tobias Gysi
llvmlistbot at llvm.org
Tue May 16 06:17:45 PDT 2023
Author: Tobias Gysi
Date: 2023-05-16T13:16:02Z
New Revision: 429582d9460513a540b43a6b2c9e1be123a885e2
URL: https://github.com/llvm/llvm-project/commit/429582d9460513a540b43a6b2c9e1be123a885e2
DIFF: https://github.com/llvm/llvm-project/commit/429582d9460513a540b43a6b2c9e1be123a885e2.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
mlir/test/Target/LLVMIR/Import/intrinsic.ll
mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index a6b3cd307932..df6947d79ae8 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -262,12 +262,17 @@ def LLVM_USubWithOverflowOp : LLVM_ArithWithOverflowOp<"usub.with.overflow">;
def LLVM_SMulWithOverflowOp : LLVM_ArithWithOverflowOp<"smul.with.overflow">;
def LLVM_UMulWithOverflowOp : LLVM_ArithWithOverflowOp<"umul.with.overflow">;
+//
+// Optimization hint intrinsics.
+//
+
def LLVM_AssumeOp
: LLVM_ZeroResultIntrOp<"assume", []>, Arguments<(ins I1:$cond)>;
-//
-// Expect intrinsics.
-//
+def LLVM_IsConstantOp : LLVM_IntrOp<"is.constant", [], [0], [Pure], 1> {
+ let arguments = (ins LLVM_Type:$val);
+ let results = (outs I1:$res);
+}
def LLVM_ExpectOp
: LLVM_OneResultIntrOp<"expect", [], [0],
diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
index fadfc124adbd..190362423940 100644
--- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -467,6 +467,14 @@ define void @assume(i1 %true) {
ret void
}
+; CHECK-LABEL: @is_constant
+; CHECK-SAME: %[[VAL:[a-zA-Z0-9]+]]
+define void @is_constant(i32 %0) {
+ ; CHECK: "llvm.intr.is.constant"(%[[VAL]]) : (i32) -> i1
+ %2 = call i1 @llvm.is.constant.i32(i32 %0)
+ ret void
+}
+
; CHECK-LABEL: @expect
; CHECK-SAME: %[[VAL:[a-zA-Z0-9]+]]
define void @expect(i32 %0) {
@@ -792,6 +800,7 @@ declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32)
declare { <8 x i32>, <8 x i1> } @llvm.smul.with.overflow.v8i32(<8 x i32>, <8 x i32>)
declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>)
+declare i1 @llvm.is.constant.i32(i32)
declare i32 @llvm.expect.i32(i32, i32)
declare i16 @llvm.expect.with.probability.i16(i16, i16, double immarg)
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index 199a6e5dd159..eb72a430aa8c 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -466,6 +466,13 @@ llvm.func @umul_with_overflow_test(%arg0: i32, %arg1: i32, %arg2: vector<8xi32>,
llvm.return
}
+// CHECK-LABEL: @is_constant
+llvm.func @is_constant(%arg0: i32) {
+ // CHECK: call i1 @llvm.is.constant.i32(i32 %{{.*}})
+ %0 = "llvm.intr.is.constant"(%arg0) : (i32) -> i1
+ llvm.return
+}
+
// CHECK-LABEL: @expect
llvm.func @expect(%arg0: i32) {
%0 = llvm.mlir.constant(42 : i32) : i32
@@ -830,6 +837,7 @@ llvm.func @lifetime(%p: !llvm.ptr) {
// CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.usub.with.overflow.v8i32(<8 x i32>, <8 x i32>)
// CHECK-DAG: declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
// CHECK-DAG: declare { <8 x i32>, <8 x i1> } @llvm.umul.with.overflow.v8i32(<8 x i32>, <8 x i32>)
+// CHECK-DAG: declare i1 @llvm.is.constant.i32(i32)
// CHECK-DAG: declare i32 @llvm.expect.i32(i32, i32)
// CHECK-DAG: declare i16 @llvm.expect.with.probability.i16(i16, i16, double immarg)
// CHECK-DAG: declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
More information about the Mlir-commits
mailing list