xref: /llvm-project/mlir/test/Bytecode/uselist_orders.mlir (revision 612781918fb01a2a0985a1c4c9200f5d5d1581cc)
1// RUN: mlir-opt %s -split-input-file --test-verify-uselistorder -verify-diagnostics
2
3// COM: --test-verify-uselistorder will randomly shuffle the uselist of every
4//      value and do a roundtrip to bytecode. An error is returned if the
5//      uselist order are not preserved when doing a roundtrip to bytecode. The
6//      test needs to verify diagnostics to be functional.
7
8func.func @base_test(%arg0 : i32) -> i32 {
9  %0 = arith.constant 45 : i32
10  %1 = arith.constant 46 : i32
11  %2 = "test.addi"(%arg0, %arg0) : (i32, i32) -> i32
12  %3 = "test.addi"(%2, %0) : (i32, i32) -> i32
13  %4 = "test.addi"(%2, %1) : (i32, i32) -> i32
14  %5 = "test.addi"(%3, %4) : (i32, i32) -> i32
15  %6 = "test.addi"(%5, %4) : (i32, i32) -> i32
16  %7 = "test.addi"(%6, %4) : (i32, i32) -> i32
17  return %7 : i32
18}
19
20// -----
21
22func.func @test_with_multiple_uses_in_same_op(%arg0 : i32) -> i32 {
23  %0 = arith.constant 45 : i32
24  %1 = arith.constant 46 : i32
25  %2 = "test.addi"(%arg0, %arg0) : (i32, i32) -> i32
26  %3 = "test.addi"(%2, %0) : (i32, i32) -> i32
27  %4 = "test.addi"(%2, %1) : (i32, i32) -> i32
28  %5 = "test.addi"(%2, %2) : (i32, i32) -> i32
29  %6 = "test.addi"(%3, %4) : (i32, i32) -> i32
30  %7 = "test.addi"(%6, %5) : (i32, i32) -> i32
31  %8 = "test.addi"(%7, %4) : (i32, i32) -> i32
32  %9 = "test.addi"(%8, %4) : (i32, i32) -> i32
33  return %9 : i32
34}
35
36// -----
37
38func.func @test_with_multiple_block_arg_uses(%arg0 : i32) -> i32 {
39  %0 = arith.constant 45 : i32
40  %1 = arith.constant 46 : i32
41  %2 = "test.addi"(%arg0, %arg0) : (i32, i32) -> i32
42  %3 = "test.addi"(%2, %arg0) : (i32, i32) -> i32
43  %4 = "test.addi"(%2, %1) : (i32, i32) -> i32
44  %5 = "test.addi"(%2, %2) : (i32, i32) -> i32
45  %6 = "test.addi"(%3, %4) : (i32, i32) -> i32
46  %7 = "test.addi"(%6, %5) : (i32, i32) -> i32
47  %8 = "test.addi"(%7, %4) : (i32, i32) -> i32
48  %9 = "test.addi"(%8, %4) : (i32, i32) -> i32
49  return %9 : i32
50}
51
52// -----
53
54// Test that use-lists in region with no dominance are preserved
55test.graph_region {
56  %0 = "test.foo"(%1) : (i32) -> i32
57  test.graph_region attributes {a} {
58    %a = "test.a"(%b) : (i32) -> i32
59    %b = "test.b"(%2) : (i32) -> i32
60  }
61  %1 = "test.bar"(%2) : (i32) -> i32
62  %2 = "test.baz"() : () -> i32
63}
64