Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Test/Passes/CastsReconciliation/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"builtin.module"() ({

^1():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
%1 = "builtin.unrealized_conversion_cast"(%0) : (i64) -> i64
Expand All @@ -11,7 +10,6 @@
"func.return"() : () -> ()
}) : () -> ()

^2():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
%1 = "builtin.unrealized_conversion_cast"(%0) : (i64) -> !riscv.reg
Expand All @@ -21,7 +19,6 @@
"func.return"() : () -> ()
}) : () -> ()

^3():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
// the remaining cast is unused
Expand All @@ -33,7 +30,6 @@
"func.return"() : () -> ()
}) : () -> ()

^4():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
// the remaining cast is used
Expand All @@ -48,7 +44,6 @@
"func.return"() : () -> ()
}) : () -> ()

^5():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
// identity cast and pairs of casts
Expand All @@ -61,7 +56,6 @@
"func.return"() : () -> ()
}) : () -> ()

^6():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
// pairs of casts
Expand All @@ -75,7 +69,6 @@
"func.return"() : () -> ()
}) : () -> ()

^7():
"func.func"() <{function_type = (!riscv.reg) -> ()}> ({
^1(%0 : !riscv.reg):
// identity cast on block argument
Expand All @@ -86,7 +79,6 @@
"func.return"() : () -> ()
}) : () -> ()

^8():
"func.func"() <{function_type = (i8) -> ()}> ({
^1(%0 : i8):
%1 = "builtin.unrealized_conversion_cast"(%0) : (i8) -> i8
Expand All @@ -95,7 +87,6 @@
"func.return"() : () -> ()
}) : () -> ()

^9():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
// pairs of casts
Expand Down
2 changes: 0 additions & 2 deletions Test/Passes/CastsReconciliation/error.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"builtin.module"() ({

^1():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
%1 = "builtin.unrealized_conversion_cast"(%0) : (i64) -> i8
Expand All @@ -14,7 +13,6 @@
"func.return"() : () -> ()
}) : () -> ()

^2():
"func.func"() <{function_type = (i64) -> ()}> ({
^1(%0 : i64):
%1 = "builtin.unrealized_conversion_cast"(%0) : (i64) -> !riscv.reg
Expand Down
3 changes: 0 additions & 3 deletions Test/Passes/DCE/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"builtin.module"() ({

// An operation that returns one unused result
^4():
"func.func"() <{function_type = (i64) -> ()}> ({
^6(%1 : i64):
%2 = "llvm.add"(%1, %1) : (i64, i64) -> i64
Expand All @@ -18,7 +17,6 @@
}) : () -> ()

// A chain of operations that is eventually unused
^5():
"func.func"() <{function_type = () -> ()}> ({
^6():
%1 = "arith.constant"() <{ "value" = 1 : i64 }> : () -> i64
Expand All @@ -34,7 +32,6 @@
}) : () -> ()

// A chain of operations that is eventually used
^6():
"func.func"() <{function_type = () -> ()}> ({
^6():
%1 = "arith.constant"() <{ "value" = 1 : i64 }> : () -> i64
Expand Down
39 changes: 39 additions & 0 deletions Test/Tools/veir_mlir_same_verdict.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
#
# Check that veir-opt and mlir-opt reach the same accept/reject verdict on a
# single test file. Used by the `VEIR_MLIR_SAME_VERDICT` lit substitution (see Test/lit.cfg).
#
# Usage: veir_mlir_same_verdict.sh <veir-opt> <mlir-opt> <test-file>
#
# Exits 0 iff both tools verify the input (both accept) or both reject it (parse
# or verification failure). Only the verdict is compared, not the diagnostic
# text, which is not stable across mlir-opt versions.
#
# veir-opt natively accepts unregistered ops such as `test.test`; mlir-opt needs
# `--allow-unregistered-dialect` to do the same, so the two invocations differ
# only by that flag.

set -u

if [ "$#" -ne 3 ]; then
echo "veir_mlir_same_verdict.sh: expected 3 arguments, got $#" >&2
exit 2
fi

veir="$1"
mlir="$2"
file="$3"

"$veir" "$file" >/dev/null 2>&1
[ $? -eq 0 ] && veir_verdict=accept || veir_verdict=reject

"$mlir" --allow-unregistered-dialect "$file" >/dev/null 2>&1
[ $? -eq 0 ] && mlir_verdict=accept || mlir_verdict=reject

if [ "$veir_verdict" = "$mlir_verdict" ]; then
echo "VEIR_MLIR_SAME_VERDICT: veir-opt and mlir-opt agree ($veir_verdict) on $file"
exit 0
fi

echo "VEIR_MLIR_SAME_VERDICT: DISAGREEMENT on $file: veir-opt=$veir_verdict mlir-opt=$mlir_verdict" >&2
exit 1
24 changes: 24 additions & 0 deletions Test/Verifier/dominance_back_edge.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: not veir-opt %s 2>&1 | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// %x is defined in the loop body but used in the loop header. The header is
// reachable from ^entry without going through ^body, so ^body does not dominate
// the header and the use of %x there is invalid.

"builtin.module"() ({
"func.func"() <{function_type = () -> i32, sym_name = "main"}> ({
^entry():
"cf.br"() [^header] : () -> ()
^body():
%x = "arith.constant"() <{"value" = 5 : i32}> : () -> i32
"cf.br"() [^header] : () -> ()
^header():
%y = "arith.addi"(%x, %x) : (i32, i32) -> i32
%c = "arith.constant"() <{"value" = 1 : i1}> : () -> i1
"cf.cond_br"(%c) [^body, ^exit] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 0, 0>}> : (i1) -> ()
^exit():
"func.return"(%y) : (i32) -> ()
}) : () -> ()
}) : () -> ()

// CHECK: arith.addi: operand 0 {{.*}} does not dominate its use
19 changes: 19 additions & 0 deletions Test/Verifier/dominance_block_argument.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: not veir-opt %s 2>&1 | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// Block arguments are subject to the same dominance rule as op results. %arg is
// an argument of ^a, but it is used in ^b, and ^a does not dominate ^b (^b is
// also reachable directly from ^entry).

"builtin.module"() ({
"func.func"() <{function_type = (i1) -> i1, sym_name = "main"}> ({
^entry(%c : i1):
"cf.cond_br"(%c, %c) [^a, ^b] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 1, 0>}> : (i1, i1) -> ()
^a(%arg : i1):
"cf.br"() [^b] : () -> ()
^b:
"func.return"(%arg) : (i1) -> ()
}) : () -> ()
}) : () -> ()

// CHECK: func.return: operand 0 {{.*}} does not dominate its use
20 changes: 20 additions & 0 deletions Test/Verifier/dominance_cross_block.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: not veir-opt %s 2>&1 | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// %x is defined in ^a but used in ^b. ^a does not dominate ^b, because ^b is
// also reachable directly from ^entry, so this violates SSA dominance even
// though every name is assigned exactly once and every use is defined.

"builtin.module"() ({
"func.func"() <{function_type = (i1) -> i32, sym_name = "main"}> ({
^entry(%c : i1):
"cf.cond_br"(%c) [^a, ^b] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 0, 0>}> : (i1) -> ()
^a:
%x = "arith.constant"() <{"value" = 42 : i32}> : () -> i32
"cf.br"() [^b] : () -> ()
^b:
"func.return"(%x) : (i32) -> ()
}) : () -> ()
}) : () -> ()

// CHECK: func.return: operand 0 {{.*}} does not dominate its use
30 changes: 30 additions & 0 deletions Test/Verifier/dominance_graph_capture.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: veir-opt %s | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// A graph region captures %x from ^A, and ^A does not dominate ^B (the block
// that owns the graph region). The capture is used in a NON-entry block (^g1)
// of the multi-block graph region. Like MLIR, dominance is only checked in
// blocks reachable from their region's entry; ^g1 has no intra-region control
// flow into it, so it is unreachable and the use is not checked. The program
// therefore verifies. (A capture used in the graph region's entry block ^g0 is
// still checked -- see dominance_graph_capture_result.mlir.)

"builtin.module"() ({
"func.func"() <{function_type = (i1) -> (), sym_name = "m"}> ({
^entry(%c : i1):
"cf.cond_br"(%c) [^A, ^B] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 0, 0>}> : (i1) -> ()
^A():
%x = "test.test"() : () -> i64
"cf.br"() [^B] : () -> ()
^B():
"test.test"() ({
^g0():
"test.test"() : () -> ()
^g1():
"test.test"(%x) : (i64) -> ()
}) : () -> ()
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()

// CHECK: "test.test"(%{{.*}}) : (i64) -> ()
24 changes: 24 additions & 0 deletions Test/Verifier/dominance_graph_capture_block_argument.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: not veir-opt %s 2>&1 | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// The block argument %arg is only available along the path through ^b. Hiding
// its use inside a nested graph region in sibling block ^a must not bypass the
// enclosing SSACFG dominance requirement.

"builtin.module"() ({
"func.func"() <{function_type = (i1) -> (), sym_name = "main"}> ({
^entry(%c : i1):
%v = "arith.constant"() <{"value" = 5 : i32}> : () -> i32
"cf.cond_br"(%c, %v) [^b, ^a] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 1, 0>}> : (i1, i32) -> ()
^b(%arg : i32):
"cf.br"() [^a] : () -> ()
^a:
"test.test"() ({
^inner:
"test.test"(%arg) : (i32) -> ()
}) : () -> ()
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()

// CHECK: test.test: operand 0 {{.*}} does not dominate its use
25 changes: 25 additions & 0 deletions Test/Verifier/dominance_graph_capture_result.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: not veir-opt %s 2>&1 | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// The use of %x is inside a graph region, where same-block operation order does
// not matter. But %x is defined in sibling CFG block ^b, and ^b does not
// dominate the graph-owning operation in ^a because ^a is reachable directly
// from ^entry.

"builtin.module"() ({
"func.func"() <{function_type = (i1) -> (), sym_name = "main"}> ({
^entry(%c : i1):
"cf.cond_br"(%c) [^b, ^a] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 0, 0>}> : (i1) -> ()
^b:
%x = "arith.constant"() <{"value" = 5 : i32}> : () -> i32
"cf.br"() [^a] : () -> ()
^a:
"test.test"() ({
^inner:
"test.test"(%x) : (i32) -> ()
}) : () -> ()
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()

// CHECK: test.test: operand 0 {{.*}} does not dominate its use
22 changes: 22 additions & 0 deletions Test/Verifier/dominance_graph_intra_ok.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: veir-opt %s | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// Inside a multi-block graph region there is no block ordering, so %a (defined in
// ^g0) may be used in the sibling block ^g1. The captured value %v dominates the
// graph-owning operation, so it is also a legal use. The program verifies.

"builtin.module"() ({
"func.func"() <{function_type = () -> (), sym_name = "m"}> ({
^entry():
%v = "test.test"() : () -> i64
"test.test"() ({
^g0():
%a = "test.test"() : () -> i64
^g1():
"test.test"(%a, %v) : (i64, i64) -> ()
}) : () -> ()
"func.return"() : () -> ()
}) : () -> ()
}) : () -> ()

// CHECK: "test.test"(%{{.*}}, %{{.*}}) : (i64, i64) -> ()
18 changes: 18 additions & 0 deletions Test/Verifier/dominance_graph_region_ok.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: veir-opt %s | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// Dominance is only required in SSACFG regions. The body of an unregistered op
// is a graph region, where a value defined in one block may be used in another
// block that it does not dominate, so this program verifies.

"builtin.module"() ({
"test.test"() ({
^bb0:
%v = "test.test"() : () -> i32
^bb1:
"test.test"(%v) : (i32) -> ()
}) : () -> ()
}) : () -> ()

// CHECK: %[[V:.*]] = "test.test"() : () -> i32
// CHECK: "test.test"(%[[V]]) : (i32) -> ()
20 changes: 20 additions & 0 deletions Test/Verifier/dominance_sibling_branch.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: not veir-opt %s 2>&1 | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// %x is defined in ^then and used in the sibling block ^else. Neither branch of
// the conditional dominates the other, so the use in ^else is not dominated by
// its definition.

"builtin.module"() ({
"func.func"() <{function_type = (i1) -> i32, sym_name = "main"}> ({
^entry(%c : i1):
"cf.cond_br"(%c) [^then, ^else] <{"branch_weights" = array<i32>, "operandSegmentSizes" = array<i32: 1, 0, 0>}> : (i1) -> ()
^then:
%x = "arith.constant"() <{"value" = 7 : i32}> : () -> i32
"func.return"(%x) : (i32) -> ()
^else:
"func.return"(%x) : (i32) -> ()
}) : () -> ()
}) : () -> ()

// CHECK: func.return: operand 0 {{.*}} does not dominate its use
20 changes: 20 additions & 0 deletions Test/Verifier/dominance_unreachable_ok.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: veir-opt %s | filecheck %s
// RUN: VEIR_MLIR_SAME_VERDICT

// Like LLVM/MLIR, the dominance check is skipped for unreachable blocks. ^dead
// has no predecessors (^entry returns), so its use of %v imposes no dominance
// requirement and the program verifies.

"builtin.module"() ({
"func.func"() <{function_type = () -> i32, sym_name = "main"}> ({
^entry():
%v = "arith.constant"() <{"value" = 0 : i32}> : () -> i32
"func.return"(%v) : (i32) -> ()
^dead():
"func.return"(%v) : (i32) -> ()
}) : () -> ()
}) : () -> ()

// CHECK: %[[V:.*]] = "arith.constant"() <{"value" = 0 : i32}> : () -> i32
// CHECK-NEXT: "func.return"(%[[V]]) : (i32) -> ()
// CHECK: "func.return"(%[[V]]) : (i32) -> ()
Loading
Loading