[Mlir-commits] [mlir] 54fb173 - [mlir][llvm] Test LLVM IR constant import separately.

Tobias Gysi llvmlistbot at llvm.org
Tue Nov 8 00:36:15 PST 2022


Author: Tobias Gysi
Date: 2022-11-08T10:35:20+02:00
New Revision: 54fb17347bc050d6145291c1cfb14d826f20a4f4

URL: https://github.com/llvm/llvm-project/commit/54fb17347bc050d6145291c1cfb14d826f20a4f4
DIFF: https://github.com/llvm/llvm-project/commit/54fb17347bc050d6145291c1cfb14d826f20a4f4.diff

LOG: [mlir][llvm] Test LLVM IR constant import separately.

The revision moves tests related to LLVM IR constant import
into a separate constant.ll file and adds tests for integer,
null and undef immediates.

Depends on D136679

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D137416

Added: 
    mlir/test/Target/LLVMIR/Import/constant.ll

Modified: 
    mlir/test/Target/LLVMIR/Import/basic.ll

Removed: 
    mlir/test/Target/LLVMIR/Import/constant-aggregate.ll


################################################################################
diff  --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll
index 05d10eeaec9d8..9c39f395521c5 100644
--- a/mlir/test/Target/LLVMIR/Import/basic.ll
+++ b/mlir/test/Target/LLVMIR/Import/basic.ll
@@ -176,13 +176,6 @@ if.end:
 }
 ; CHECK-DBG: } loc(#[[UNKNOWNLOC]])
 
-; CHECK-LABEL: llvm.func @f3() -> !llvm.ptr<i32>
-define i32* @f3() {
-; CHECK: %[[c:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm.ptr<f64>
-; CHECK: %[[b:[0-9]+]] = llvm.bitcast %[[c]] : !llvm.ptr<f64> to !llvm.ptr<i32>
-; CHECK: llvm.return %[[b]] : !llvm.ptr<i32>
-  ret i32* bitcast (double* @g2 to i32*)
-}
 
 ; CHECK-LABEL: llvm.func @f6(%arg0: !llvm.ptr<func<void (i16)>>)
 define void @f6(void (i16) *%fn) {
@@ -192,61 +185,6 @@ define void @f6(void (i16) *%fn) {
   ret void
 }
 
-; Testing rest of the floating point constant kinds.
-; CHECK-LABEL: llvm.func @FPConstant(%arg0: f16, %arg1: bf16, %arg2: f128, %arg3: f80)
-define void @FPConstant(half %a, bfloat %b, fp128 %c, x86_fp80 %d) {
-  ; CHECK: %[[C0:.+]] = llvm.mlir.constant(1.000000e+00 : f16) : f16
-  ; CHECK: %[[C1:.+]] = llvm.mlir.constant(1.000000e+00 : bf16) : bf16
-  ; CHECK: %[[C2:.+]] = llvm.mlir.constant(0.000000e+00 : f128) : f128
-  ; CHECK: %[[C3:.+]] = llvm.mlir.constant(7.000000e+00 : f80) : f80
-
-  ; CHECK: llvm.fadd %[[C0]], %arg0  : f16
-  %1 = fadd half 1.0, %a
-  ; CHECK: llvm.fadd %[[C1]], %arg1  : bf16
-  %2 = fadd bfloat 1.0, %b
-  ; CHECK: llvm.fadd %[[C2]], %arg2  : f128
-  %3 = fadd fp128 0xL00000000000000000000000000000000, %c
-  ; CHECK: llvm.fadd %[[C3]], %arg3  : f80
-  %4 = fadd x86_fp80 0xK4001E000000000000000, %d
-  ret void
-}
-
-;
-; Functions as constants.
-;
-
-; Calling the function that has not been defined yet.
-; CHECK-LABEL: @precaller
-define i32 @precaller() {
-  %1 = alloca i32 ()*
-  ; CHECK: %[[func:.*]] = llvm.mlir.addressof @callee : !llvm.ptr<func<i32 ()>>
-  ; CHECK: llvm.store %[[func]], %[[loc:.*]]
-  store i32 ()* @callee, i32 ()** %1
-  ; CHECK: %[[indir:.*]] = llvm.load %[[loc]]
-  %2 = load i32 ()*, i32 ()** %1
-  ; CHECK: llvm.call %[[indir]]()
-  %3 = call i32 %2()
-  ret i32 %3
-}
-
-define i32 @callee() {
-  ret i32 42
-}
-
-; Calling the function that has been defined.
-; CHECK-LABEL: @postcaller
-define i32 @postcaller() {
-  %1 = alloca i32 ()*
-  ; CHECK: %[[func:.*]] = llvm.mlir.addressof @callee : !llvm.ptr<func<i32 ()>>
-  ; CHECK: llvm.store %[[func]], %[[loc:.*]]
-  store i32 ()* @callee, i32 ()** %1
-  ; CHECK: %[[indir:.*]] = llvm.load %[[loc]]
-  %2 = load i32 ()*, i32 ()** %1
-  ; CHECK: llvm.call %[[indir]]()
-  %3 = call i32 %2()
-  ret i32 %3
-}
-
 @_ZTIi = external dso_local constant i8*
 @_ZTIii= external dso_local constant i8**
 declare void @foo(i8*)

diff  --git a/mlir/test/Target/LLVMIR/Import/constant-aggregate.ll b/mlir/test/Target/LLVMIR/Import/constant-aggregate.ll
deleted file mode 100644
index 955cf47779664..0000000000000
--- a/mlir/test/Target/LLVMIR/Import/constant-aggregate.ll
+++ /dev/null
@@ -1,40 +0,0 @@
-; RUN: mlir-translate --import-llvm %s | FileCheck %s
-; CHECK: %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"SimpleAggType", (i32, i8, i16, i32)>
-; CHECK: %[[C0:.+]] = llvm.mlir.constant(9 : i32) : i32
-; CHECK: %[[CHAIN0:.+]] = llvm.insertvalue %[[C0]], %[[ROOT]][0]
-; CHECK: %[[C1:.+]] = llvm.mlir.constant(4 : i8) : i8
-; CHECK: %[[CHAIN1:.+]] = llvm.insertvalue %[[C1]], %[[CHAIN0]][1]
-; CHECK: %[[C2:.+]] = llvm.mlir.constant(8 : i16) : i16
-; CHECK: %[[CHAIN2:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN1]][2]
-; CHECK: %[[C3:.+]] = llvm.mlir.constant(7 : i32) : i32
-; CHECK: %[[CHAIN3:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN2]][3]
-; CHECK: llvm.return %[[CHAIN3]]
-%SimpleAggType = type {i32, i8, i16, i32}
- at simpleAgg = global %SimpleAggType {i32 9, i8 4, i16 8, i32 7}
-
-; CHECK: %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"NestedAggType", (struct<"SimpleAggType", (i32, i8, i16, i32)>, ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>)>
-; CHECK: %[[NESTED:.+]] = llvm.mlir.undef : !llvm.struct<"SimpleAggType", (i32, i8, i16, i32)>
-; CHECK: %[[C1:.+]] = llvm.mlir.constant(1 : i32) : i32
-; CHECK: %[[CHAIN0:.+]] = llvm.insertvalue %[[C1]], %[[NESTED]][0]
-; CHECK: %[[C2:.+]] = llvm.mlir.constant(2 : i8) : i8
-; CHECK: %[[CHAIN1:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN0]][1]
-; CHECK: %[[C3:.+]] = llvm.mlir.constant(3 : i16) : i16
-; CHECK: %[[CHAIN2:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN1]][2]
-; CHECK: %[[C4:.+]] = llvm.mlir.constant(4 : i32) : i32
-; CHECK: %[[CHAIN3:.+]] = llvm.insertvalue %[[C4]], %[[CHAIN2]][3]
-; CHECK: %[[CHAIN4:.+]] = llvm.insertvalue %[[CHAIN3]], %[[ROOT]][0]
-; CHECK: %[[NP:.+]] = llvm.mlir.null : !llvm.ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>
-; CHECK: %[[CHAIN5:.+]] = llvm.insertvalue %[[NP]], %[[CHAIN4]][1]
-; CHECK: llvm.return %[[CHAIN5]]
-%NestedAggType = type {%SimpleAggType, %SimpleAggType*}
- at nestedAgg = global %NestedAggType { %SimpleAggType{i32 1, i8 2, i16 3, i32 4}, %SimpleAggType* null }
-
-; CHECK: %[[ROOT:.+]] = llvm.mlir.undef : !llvm.vec<2 x ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>>
-; CHECK: %[[C0:.+]] = llvm.mlir.null : !llvm.ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>
-; CHECK: %[[P0:.+]] = llvm.mlir.constant(0 : i32) : i32
-; CHECK: %[[CHAIN0:.+]] = llvm.insertelement %[[C0]], %[[ROOT]][%[[P0]] : i32] : !llvm.vec<2 x ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>>
-; CHECK: %[[C1:.+]] = llvm.mlir.null : !llvm.ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>
-; CHECK: %[[P1:.+]] = llvm.mlir.constant(1 : i32) : i32
-; CHECK: %[[CHAIN1:.+]] = llvm.insertelement %[[C1]], %[[CHAIN0]][%[[P1]] : i32] : !llvm.vec<2 x ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>>
-; CHECK: llvm.return %[[CHAIN1]] : !llvm.vec<2 x ptr<struct<"SimpleAggType", (i32, i8, i16, i32)>>>
- at vectorAgg = global <2 x %SimpleAggType*> <%SimpleAggType* null, %SimpleAggType* null>

diff  --git a/mlir/test/Target/LLVMIR/Import/constant.ll b/mlir/test/Target/LLVMIR/Import/constant.ll
new file mode 100644
index 0000000000000..167e5c4194014
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/constant.ll
@@ -0,0 +1,160 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+; CHECK-LABEL: @int_constants
+define void @int_constants(i16 %arg0, i32 %arg1, i1 %arg2) {
+  ; CHECK:  %[[C0:.+]] = llvm.mlir.constant(42 : i16) : i16
+  ; CHECK:  %[[C1:.+]] = llvm.mlir.constant(7 : i32) : i32
+  ; CHECK:  %[[C2:.+]] = llvm.mlir.constant(true) : i1
+
+  ; CHECK:  llvm.add %[[C0]], %{{.*}} : i16
+  %1 = add i16 42, %arg0
+  ; CHECK:  llvm.add %[[C1]], %{{.*}} : i32
+  %2 = add i32 7, %arg1
+  ; CHECK:  llvm.or %[[C2]], %{{.*}} : i1
+  %3 = or i1 1, %arg2
+  ret void
+}
+
+; // -----
+
+; CHECK-LABEL: @float_constants
+define void @float_constants(half %arg0, bfloat %arg1, fp128 %arg2, x86_fp80 %arg3) {
+  ; CHECK:  %[[C0:.+]] = llvm.mlir.constant(1.000000e+00 : f16) : f16
+  ; CHECK:  %[[C1:.+]] = llvm.mlir.constant(1.000000e+00 : bf16) : bf16
+  ; CHECK:  %[[C2:.+]] = llvm.mlir.constant(0.000000e+00 : f128) : f128
+  ; CHECK:  %[[C3:.+]] = llvm.mlir.constant(7.000000e+00 : f80) : f80
+
+  ; CHECK:  llvm.fadd %[[C0]], %{{.*}} : f16
+  %1 = fadd half 1.0, %arg0
+  ; CHECK:  llvm.fadd %[[C1]], %{{.*}} : bf16
+  %2 = fadd bfloat 1.0, %arg1
+  ; CHECK:  llvm.fadd %[[C2]], %{{.*}} : f128
+  %3 = fadd fp128 0xL00000000000000000000000000000000, %arg2
+  ; CHECK:  llvm.fadd %[[C3]], %{{.*}} : f80
+  %4 = fadd x86_fp80 0xK4001E000000000000000, %arg3
+  ret void
+}
+
+; // -----
+
+; CHECK-LABEL: @undef_constant
+define void @undef_constant(i32 %arg0) {
+  ; CHECK:  %[[UNDEF:.+]] = llvm.mlir.undef : i32
+  ; CHECK:  llvm.add %[[UNDEF]], %{{.*}} : i32
+  %1 = add i32 undef, %arg0
+  ret void
+}
+
+; // -----
+
+; CHECK-LABEL: @null_constant
+define i32* @null_constant() {
+  ; CHECK:  %[[NULL:[0-9]+]] = llvm.mlir.null : !llvm.ptr<i32>
+  ; CHECK:  llvm.return %[[NULL]] : !llvm.ptr<i32>
+  ret i32* bitcast (double* null to i32*)
+}
+
+; // -----
+
+ at global = external global double, align 8
+
+; CHECK-LABEL: @bitcast_const_expr
+define i32* @bitcast_const_expr() {
+  ; CHECK:  %[[VAL0:.*]] = llvm.mlir.addressof @global : !llvm.ptr<f64>
+  ; CHECK:  %[[VAL1:.*]] = llvm.bitcast %[[VAL0]] : !llvm.ptr<f64> to !llvm.ptr<i32>
+  ; CHECK:  llvm.return %[[VAL1]] : !llvm.ptr<i32>
+  ret i32* bitcast (double* @global to i32*)
+}
+
+; // -----
+
+ at global = external global i32, align 8
+
+; CHECK-LABEL: @gep_const_expr
+define i32* @gep_const_expr() {
+  ; CHECK:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr<i32>
+  ; CHECK:  %[[IDX:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
+  ; CHECK:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr<i32>, i32) -> !llvm.ptr<i32>
+  ; CHECK:  llvm.return %[[GEP]] : !llvm.ptr<i32>
+  ret i32* getelementptr (i32, i32* @global, i32 2)
+}
+
+; // -----
+
+; Verify the function constant import.
+
+; Calling a function that has not been defined yet.
+; CHECK-LABEL: @function_address_before_def
+define i32 @function_address_before_def() {
+  %1 = alloca i32 ()*
+  ; CHECK:  %[[FUN:.*]] = llvm.mlir.addressof @callee : !llvm.ptr<func<i32 ()>>
+  ; CHECK:  llvm.store %[[FUN]], %[[PTR:.*]]
+  store i32 ()* @callee, i32 ()** %1
+  ; CHECK:  %[[INDIR:.*]] = llvm.load %[[PTR]]
+  %2 = load i32 ()*, i32 ()** %1
+  ; CHECK:  llvm.call %[[INDIR]]()
+  %3 = call i32 %2()
+  ret i32 %3
+}
+
+define i32 @callee() {
+  ret i32 42
+}
+
+; Calling a function that has been defined.
+; CHECK-LABEL: @function_address_after_def
+define i32 @function_address_after_def() {
+  %1 = alloca i32 ()*
+  ; CHECK:  %[[FUN:.*]] = llvm.mlir.addressof @callee : !llvm.ptr<func<i32 ()>>
+  ; CHECK:  llvm.store %[[FUN]], %[[PTR:.*]]
+  store i32 ()* @callee, i32 ()** %1
+  ; CHECK:  %[[INDIR:.*]] = llvm.load %[[PTR]]
+  %2 = load i32 ()*, i32 ()** %1
+  ; CHECK:  llvm.call %[[INDIR]]()
+  %3 = call i32 %2()
+  ret i32 %3
+}
+
+; // -----
+
+; Verify the aggregate constant import.
+
+; CHECK:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"simple_agg_type", (i32, i8, i16, i32)>
+; CHECK:  %[[C0:.+]] = llvm.mlir.constant(9 : i32) : i32
+; CHECK:  %[[CHAIN0:.+]] = llvm.insertvalue %[[C0]], %[[ROOT]][0]
+; CHECK:  %[[C1:.+]] = llvm.mlir.constant(4 : i8) : i8
+; CHECK:  %[[CHAIN1:.+]] = llvm.insertvalue %[[C1]], %[[CHAIN0]][1]
+; CHECK:  %[[C2:.+]] = llvm.mlir.constant(8 : i16) : i16
+; CHECK:  %[[CHAIN2:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN1]][2]
+; CHECK:  %[[C3:.+]] = llvm.mlir.constant(7 : i32) : i32
+; CHECK:  %[[CHAIN3:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN2]][3]
+; CHECK:  llvm.return %[[CHAIN3]]
+%simple_agg_type = type {i32, i8, i16, i32}
+ at simple_agg = global %simple_agg_type {i32 9, i8 4, i16 8, i32 7}
+
+; CHECK:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"nested_agg_type", (struct<"simple_agg_type", (i32, i8, i16, i32)>, ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>)>
+; CHECK:  %[[NESTED:.+]] = llvm.mlir.undef : !llvm.struct<"simple_agg_type", (i32, i8, i16, i32)>
+; CHECK:  %[[C1:.+]] = llvm.mlir.constant(1 : i32) : i32
+; CHECK:  %[[CHAIN0:.+]] = llvm.insertvalue %[[C1]], %[[NESTED]][0]
+; CHECK:  %[[C2:.+]] = llvm.mlir.constant(2 : i8) : i8
+; CHECK:  %[[CHAIN1:.+]] = llvm.insertvalue %[[C2]], %[[CHAIN0]][1]
+; CHECK:  %[[C3:.+]] = llvm.mlir.constant(3 : i16) : i16
+; CHECK:  %[[CHAIN2:.+]] = llvm.insertvalue %[[C3]], %[[CHAIN1]][2]
+; CHECK:  %[[C4:.+]] = llvm.mlir.constant(4 : i32) : i32
+; CHECK:  %[[CHAIN3:.+]] = llvm.insertvalue %[[C4]], %[[CHAIN2]][3]
+; CHECK:  %[[CHAIN4:.+]] = llvm.insertvalue %[[CHAIN3]], %[[ROOT]][0]
+; CHECK:  %[[NP:.+]] = llvm.mlir.null : !llvm.ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>
+; CHECK:  %[[CHAIN5:.+]] = llvm.insertvalue %[[NP]], %[[CHAIN4]][1]
+; CHECK:  llvm.return %[[CHAIN5]]
+%nested_agg_type = type {%simple_agg_type, %simple_agg_type*}
+ at nested_agg = global %nested_agg_type { %simple_agg_type{i32 1, i8 2, i16 3, i32 4}, %simple_agg_type* null }
+
+; CHECK:  %[[ROOT:.+]] = llvm.mlir.undef : !llvm.vec<2 x ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>>
+; CHECK:  %[[C0:.+]] = llvm.mlir.null : !llvm.ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>
+; CHECK:  %[[P0:.+]] = llvm.mlir.constant(0 : i32) : i32
+; CHECK:  %[[CHAIN0:.+]] = llvm.insertelement %[[C0]], %[[ROOT]][%[[P0]] : i32] : !llvm.vec<2 x ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>>
+; CHECK:  %[[C1:.+]] = llvm.mlir.null : !llvm.ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>
+; CHECK:  %[[P1:.+]] = llvm.mlir.constant(1 : i32) : i32
+; CHECK:  %[[CHAIN1:.+]] = llvm.insertelement %[[C1]], %[[CHAIN0]][%[[P1]] : i32] : !llvm.vec<2 x ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>>
+; CHECK:  llvm.return %[[CHAIN1]] : !llvm.vec<2 x ptr<struct<"simple_agg_type", (i32, i8, i16, i32)>>>
+ at vector_agg = global <2 x %simple_agg_type*> <%simple_agg_type* null, %simple_agg_type* null>


        


More information about the Mlir-commits mailing list