Commit 429582d9 authored by Tobias Gysi's avatar Tobias Gysi
Browse files

[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
parent ddb27b18
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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],
+9 −0
Original line number Diff line number Diff line
@@ -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)
+8 −0
Original line number Diff line number Diff line
@@ -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)