|
| 1 | +// REQUIRES: z3-prover |
| 2 | +// RUN: mlir-translate --export-smtlib %s | z3 -in 2>&1 | FileCheck %s |
| 3 | +// RUN: mlir-translate --export-smtlib --smtlibexport-inline-single-use-values %s | z3 -in 2>&1 | FileCheck %s |
| 4 | + |
| 5 | +// Function and constant symbol declarations, uninterpreted sorts |
| 6 | +smt.solver () : () -> () { |
| 7 | + %0 = smt.declare_fun "b" : !smt.bv<32> |
| 8 | + %1 = smt.declare_fun : !smt.int |
| 9 | + %2 = smt.declare_fun : !smt.func<(!smt.int, !smt.bv<32>) !smt.bool> |
| 10 | + %3 = smt.apply_func %2(%1, %0) : !smt.func<(!smt.int, !smt.bv<32>) !smt.bool> |
| 11 | + smt.assert %3 |
| 12 | + |
| 13 | + %4 = smt.declare_fun : !smt.sort<"uninterpreted"> |
| 14 | + %5 = smt.declare_fun : !smt.sort<"other"[!smt.sort<"uninterpreted">]> |
| 15 | + %6 = smt.declare_fun : !smt.func<(!smt.sort<"other"[!smt.sort<"uninterpreted">]>, !smt.sort<"uninterpreted">) !smt.bool> |
| 16 | + %7 = smt.apply_func %6(%5, %4) : !smt.func<(!smt.sort<"other"[!smt.sort<"uninterpreted">]>, !smt.sort<"uninterpreted">) !smt.bool> |
| 17 | + smt.assert %7 |
| 18 | + |
| 19 | + smt.check sat {} unknown {} unsat {} |
| 20 | +} |
| 21 | + |
| 22 | +// CHECK-NOT: WARNING |
| 23 | +// CHECK-NOT: warning |
| 24 | +// CHECK-NOT: ERROR |
| 25 | +// CHECK-NOT: error |
| 26 | +// CHECK-NOT: unsat |
| 27 | +// CHECK: sat |
| 28 | + |
| 29 | +// Big expression |
| 30 | +smt.solver () : () -> () { |
| 31 | + %true = smt.constant true |
| 32 | + %false = smt.constant false |
| 33 | + %0 = smt.not %true |
| 34 | + %1 = smt.and %0, %true, %false |
| 35 | + %2 = smt.or %1, %0, %true |
| 36 | + %3 = smt.xor %0, %2 |
| 37 | + %4 = smt.implies %3, %false |
| 38 | + %5 = smt.implies %4, %true |
| 39 | + smt.assert %5 |
| 40 | + |
| 41 | + smt.check sat {} unknown {} unsat {} |
| 42 | +} |
| 43 | + |
| 44 | +// CHECK-NOT: WARNING |
| 45 | +// CHECK-NOT: warning |
| 46 | +// CHECK-NOT: ERROR |
| 47 | +// CHECK-NOT: error |
| 48 | +// CHECK-NOT: unsat |
| 49 | +// CHECK: sat |
| 50 | + |
| 51 | +// Constant array |
| 52 | +smt.solver () : () -> () { |
| 53 | + %true = smt.constant true |
| 54 | + %false = smt.constant false |
| 55 | + %c = smt.int.constant 0 |
| 56 | + %0 = smt.array.broadcast %true : !smt.array<[!smt.int -> !smt.bool]> |
| 57 | + %1 = smt.array.store %0[%c], %false : !smt.array<[!smt.int -> !smt.bool]> |
| 58 | + %2 = smt.array.select %1[%c] : !smt.array<[!smt.int -> !smt.bool]> |
| 59 | + smt.assert %2 |
| 60 | + |
| 61 | + smt.check sat {} unknown {} unsat {} |
| 62 | +} |
| 63 | + |
| 64 | +// CHECK-NOT: WARNING |
| 65 | +// CHECK-NOT: warning |
| 66 | +// CHECK-NOT: ERROR |
| 67 | +// CHECK-NOT: error |
| 68 | +// CHECK: unsat |
| 69 | + |
| 70 | +// BitVector extract and concat, and constants |
| 71 | +smt.solver () : () -> () { |
| 72 | + %xf = smt.bv.constant #smt.bv<0xf> : !smt.bv<4> |
| 73 | + %x0 = smt.bv.constant #smt.bv<0> : !smt.bv<4> |
| 74 | + %xff = smt.bv.constant #smt.bv<0xff> : !smt.bv<8> |
| 75 | + |
| 76 | + %0 = smt.bv.concat %xf, %x0 : !smt.bv<4>, !smt.bv<4> |
| 77 | + %1 = smt.bv.extract %0 from 4 : (!smt.bv<8>) -> !smt.bv<4> |
| 78 | + %2 = smt.bv.repeat 2 times %1 : !smt.bv<4> |
| 79 | + %3 = smt.eq %2, %xff : !smt.bv<8> |
| 80 | + smt.assert %3 |
| 81 | + |
| 82 | + smt.check sat {} unknown {} unsat {} |
| 83 | +} |
| 84 | + |
| 85 | +// CHECK-NOT: WARNING |
| 86 | +// CHECK-NOT: warning |
| 87 | +// CHECK-NOT: ERROR |
| 88 | +// CHECK-NOT: error |
| 89 | +// CHECK-NOT: unsat |
| 90 | +// CHECK: sat |
| 91 | + |
| 92 | +// Quantifiers |
| 93 | +smt.solver () : () -> () { |
| 94 | + %1 = smt.forall ["a"] { |
| 95 | + ^bb0(%arg2: !smt.int): |
| 96 | + %c2_1 = smt.int.constant 2 |
| 97 | + %2 = smt.int.mul %arg2, %c2_1 |
| 98 | + |
| 99 | + %3 = smt.exists { |
| 100 | + ^bb0(%arg1: !smt.int): |
| 101 | + %c2 = smt.int.constant 2 |
| 102 | + %4 = smt.int.mul %c2, %arg1 |
| 103 | + %5 = smt.eq %4, %2 : !smt.int |
| 104 | + smt.yield %5 : !smt.bool |
| 105 | + } |
| 106 | + |
| 107 | + smt.yield %3 : !smt.bool |
| 108 | + } |
| 109 | + smt.assert %1 |
| 110 | + |
| 111 | + smt.check sat {} unknown {} unsat {} |
| 112 | +} |
| 113 | + |
| 114 | +// CHECK-NOT: WARNING |
| 115 | +// CHECK-NOT: warning |
| 116 | +// CHECK-NOT: ERROR |
| 117 | +// CHECK-NOT: error |
| 118 | +// CHECK-NOT: unsat |
| 119 | +// CHECK: sat |
| 120 | + |
| 121 | +// Push and pop |
| 122 | +smt.solver () : () -> () { |
| 123 | + %three = smt.int.constant 3 |
| 124 | + %four = smt.int.constant 4 |
| 125 | + %unsat_eq = smt.eq %three, %four : !smt.int |
| 126 | + %sat_eq = smt.eq %three, %three : !smt.int |
| 127 | + |
| 128 | + smt.push 1 |
| 129 | + smt.assert %unsat_eq |
| 130 | + smt.check sat {} unknown {} unsat {} |
| 131 | + smt.pop 1 |
| 132 | + smt.assert %sat_eq |
| 133 | + smt.check sat {} unknown {} unsat {} |
| 134 | +} |
| 135 | + |
| 136 | +// CHECK-NOT: WARNING |
| 137 | +// CHECK-NOT: warning |
| 138 | +// CHECK-NOT: ERROR |
| 139 | +// CHECK-NOT: error |
| 140 | +// CHECK-NOT: sat |
| 141 | +// CHECK: unsat |
| 142 | +// CHECK-NOT: WARNING |
| 143 | +// CHECK-NOT: warning |
| 144 | +// CHECK-NOT: ERROR |
| 145 | +// CHECK-NOT: error |
| 146 | +// CHECK-NOT: unsat |
| 147 | +// CHECK: sat |
| 148 | + |
| 149 | +// Reset |
| 150 | +smt.solver () : () -> () { |
| 151 | + %three = smt.int.constant 3 |
| 152 | + %four = smt.int.constant 4 |
| 153 | + %unsat_eq = smt.eq %three, %four : !smt.int |
| 154 | + %sat_eq = smt.eq %three, %three : !smt.int |
| 155 | + |
| 156 | + smt.assert %unsat_eq |
| 157 | + smt.check sat {} unknown {} unsat {} |
| 158 | + smt.reset |
| 159 | + smt.assert %sat_eq |
| 160 | + smt.check sat {} unknown {} unsat {} |
| 161 | +} |
| 162 | + |
| 163 | +// CHECK-NOT: WARNING |
| 164 | +// CHECK-NOT: warning |
| 165 | +// CHECK-NOT: ERROR |
| 166 | +// CHECK-NOT: error |
| 167 | +// CHECK-NOT: sat |
| 168 | +// CHECK: unsat |
| 169 | +// CHECK-NOT: WARNING |
| 170 | +// CHECK-NOT: warning |
| 171 | +// CHECK-NOT: ERROR |
| 172 | +// CHECK-NOT: error |
| 173 | +// CHECK-NOT: unsat |
| 174 | +// CHECK: sat |
| 175 | + |
| 176 | +smt.solver () : () -> () { |
| 177 | + smt.set_logic "HORN" |
| 178 | + %c = smt.declare_fun : !smt.int |
| 179 | + %c4 = smt.int.constant 4 |
| 180 | + %eq = smt.eq %c, %c4 : !smt.int |
| 181 | + smt.assert %eq |
| 182 | + smt.check sat {} unknown {} unsat {} |
| 183 | +} |
| 184 | + |
| 185 | +// CHECK-NOT: WARNING |
| 186 | +// CHECK-NOT: warning |
| 187 | +// CHECK-NOT: ERROR |
| 188 | +// CHECK-NOT: error |
| 189 | +// CHECK-NOT: unsat |
| 190 | +// CHECK-NOT: sat |
| 191 | +// CHECK: unknown |
0 commit comments