diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td @@ -262,12 +262,17 @@ 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 --- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll +++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll @@ -467,6 +467,14 @@ 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 { <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 --- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir +++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir @@ -466,6 +466,13 @@ 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 @@ // 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)