18 changes: 9 additions & 9 deletions mlir/test/Transforms/buffer-deallocation.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func @memref_in_function_results(
func @nested_region_control_flow(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand Down Expand Up @@ -628,7 +628,7 @@ func @nested_region_control_flow(
func @nested_region_control_flow_div(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand Down Expand Up @@ -844,7 +844,7 @@ func @nestedRegionsAndCondBranchAlloca(
func @nestedRegionControlFlowAlloca(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand Down Expand Up @@ -878,7 +878,7 @@ func @loop_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = alloc() : memref<2xf32>
scf.yield %3 : memref<2xf32>
}
Expand Down Expand Up @@ -921,7 +921,7 @@ func @loop_nested_if_no_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = scf.if %2 -> (memref<2xf32>) {
scf.yield %0 : memref<2xf32>
} else {
Expand Down Expand Up @@ -961,7 +961,7 @@ func @loop_nested_if_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = scf.if %2 -> (memref<2xf32>) {
%4 = alloc() : memref<2xf32>
scf.yield %4 : memref<2xf32>
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func @loop_nested_alloc(
%3 = scf.for %i3 = %lb to %ub step %step
iter_args(%iterBuf3 = %iterBuf2) -> memref<2xf32> {
%4 = alloc() : memref<2xf32>
%5 = cmpi "eq", %i, %ub : index
%5 = cmpi eq, %i, %ub : index
%6 = scf.if %5 -> (memref<2xf32>) {
%7 = alloc() : memref<2xf32>
scf.yield %7 : memref<2xf32>
Expand Down Expand Up @@ -1104,7 +1104,7 @@ func @loop_dynalloc(
br ^loopHeader(%const0, %arg2 : i32, memref<?xf32>)

^loopHeader(%i : i32, %buff : memref<?xf32>):
%lessThan = cmpi "slt", %i, %arg1 : i32
%lessThan = cmpi slt, %i, %arg1 : i32
cond_br %lessThan,
^loopBody(%i, %buff : i32, memref<?xf32>),
^exit(%buff : memref<?xf32>)
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func @do_loop_alloc(
br ^loopHeader(%inc, %alloc1 : i32, memref<2xf32>)

^loopHeader(%i : i32, %buff : memref<2xf32>):
%lessThan = cmpi "slt", %i, %arg1 : i32
%lessThan = cmpi slt, %i, %arg1 : i32
cond_br %lessThan,
^loopBody(%i, %buff : i32, memref<2xf32>),
^exit(%buff : memref<2xf32>)
Expand Down
14 changes: 7 additions & 7 deletions mlir/test/Transforms/buffer-hoisting.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func @nested_regions_and_cond_branch(
func @nested_region_control_flow(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand All @@ -410,7 +410,7 @@ func @nested_region_control_flow(
func @nested_region_control_flow_div(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand All @@ -436,7 +436,7 @@ func @nested_region_control_flow_div(
func @nested_region_control_flow_div_nested(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
%3 = scf.if %0 -> (memref<?x?xf32>) {
Expand Down Expand Up @@ -621,7 +621,7 @@ func @loop_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = alloc() : memref<2xf32>
scf.yield %3 : memref<2xf32>
}
Expand All @@ -648,7 +648,7 @@ func @loop_nested_if_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = scf.if %2 -> (memref<2xf32>) {
%4 = alloc() : memref<2xf32>
scf.yield %4 : memref<2xf32>
Expand Down Expand Up @@ -685,7 +685,7 @@ func @loop_nested_alloc(
%3 = scf.for %i3 = %lb to %ub step %step
iter_args(%iterBuf3 = %iterBuf2) -> memref<2xf32> {
%4 = alloc() : memref<2xf32>
%5 = cmpi "eq", %i, %ub : index
%5 = cmpi eq, %i, %ub : index
%6 = scf.if %5 -> (memref<2xf32>) {
%7 = alloc() : memref<2xf32>
scf.yield %7 : memref<2xf32>
Expand Down Expand Up @@ -726,7 +726,7 @@ func @loop_nested_alloc_dyn_dependency(
iter_args(%iterBuf2 = %iterBuf) -> memref<?xf32> {
%3 = scf.for %i3 = %lb to %ub step %step
iter_args(%iterBuf3 = %iterBuf2) -> memref<?xf32> {
%5 = cmpi "eq", %i, %ub : index
%5 = cmpi eq, %i, %ub : index
%6 = scf.if %5 -> (memref<?xf32>) {
%7 = alloc(%i3) : memref<?xf32>
scf.yield %7 : memref<?xf32>
Expand Down
14 changes: 7 additions & 7 deletions mlir/test/Transforms/buffer-loop-hoisting.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func @nested_regions_and_cond_branch(
func @nested_region_control_flow(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand Down Expand Up @@ -141,7 +141,7 @@ func @loop_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = alloc() : memref<2xf32>
scf.yield %3 : memref<2xf32>
}
Expand All @@ -168,7 +168,7 @@ func @loop_nested_if_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = scf.if %2 -> (memref<2xf32>) {
%4 = alloc() : memref<2xf32>
scf.yield %4 : memref<2xf32>
Expand Down Expand Up @@ -206,7 +206,7 @@ func @loop_nested_alloc(
%3 = scf.for %i3 = %lb to %ub step %step
iter_args(%iterBuf3 = %iterBuf2) -> memref<2xf32> {
%4 = alloc() : memref<2xf32>
%5 = cmpi "eq", %i, %ub : index
%5 = cmpi eq, %i, %ub : index
%6 = scf.if %5 -> (memref<2xf32>) {
%7 = alloc() : memref<2xf32>
%8 = alloc() : memref<2xf32>
Expand Down Expand Up @@ -253,7 +253,7 @@ func @loop_nested_alloc_dyn_dependency(
%3 = scf.for %i3 = %lb to %ub step %step
iter_args(%iterBuf3 = %iterBuf2) -> memref<?xf32> {
%4 = alloc(%i3) : memref<?xf32>
%5 = cmpi "eq", %i, %ub : index
%5 = cmpi eq, %i, %ub : index
%6 = scf.if %5 -> (memref<?xf32>) {
%7 = alloc(%i3) : memref<?xf32>
scf.yield %7 : memref<?xf32>
Expand Down Expand Up @@ -360,7 +360,7 @@ func @no_hoist_one_loop_conditional(
%res: memref<2xf32>) {
%0 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%1 = cmpi "eq", %i, %ub : index
%1 = cmpi eq, %i, %ub : index
%2 = scf.if %1 -> (memref<2xf32>) {
%3 = alloc() : memref<2xf32>
scf.yield %3 : memref<2xf32>
Expand All @@ -387,7 +387,7 @@ func @hoist_one_loop_conditional(
%buf: memref<2xf32>,
%res: memref<2xf32>) {
%0 = alloc() : memref<2xf32>
%1 = cmpi "eq", %lb, %ub : index
%1 = cmpi eq, %lb, %ub : index
%2 = scf.if %1 -> (memref<2xf32>) {
%3 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Transforms/canonicalize-block-merge.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func private @print(%arg0: i32, %arg1: i32)
// CHECK-LABEL: @nomerge
func @nomerge(%arg0: i32, %i: i32) {
%c1_i32 = constant 1 : i32
%icmp = cmpi "slt", %i, %arg0 : i32
%icmp = cmpi slt, %i, %arg0 : i32
cond_br %icmp, ^bb2, ^bb3

^bb2: // pred: ^bb1
Expand All @@ -243,7 +243,7 @@ func @nomerge(%arg0: i32, %i: i32) {
br ^bb4(%jp1 : i32)

^bb4(%j: i32): // 2 preds: ^bb2, ^bb7
%jcmp = cmpi "slt", %j, %arg0 : i32
%jcmp = cmpi slt, %j, %arg0 : i32
// CHECK-NOT: call @print(%[[arg1:.+]], %[[arg1]])
call @print(%j, %ip1) : (i32, i32) -> ()
cond_br %jcmp, ^bb7, ^bb3
Expand Down
12 changes: 6 additions & 6 deletions mlir/test/Transforms/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,15 @@ func @lowered_affine_mod() -> (index, index) {
%c42 = constant 42 : index
%0 = remi_signed %c-43, %c42 : index
%c0 = constant 0 : index
%1 = cmpi "slt", %0, %c0 : index
%1 = cmpi slt, %0, %c0 : index
%2 = addi %0, %c42 : index
%3 = select %1, %2, %0 : index
// CHECK-NEXT: {{.*}} = constant 1 : index
%c43 = constant 43 : index
%c42_0 = constant 42 : index
%4 = remi_signed %c43, %c42_0 : index
%c0_1 = constant 0 : index
%5 = cmpi "slt", %4, %c0_1 : index
%5 = cmpi slt, %4, %c0_1 : index
%6 = addi %4, %c42_0 : index
%7 = select %5, %6, %4 : index
return %3, %7 : index, index
Expand All @@ -603,7 +603,7 @@ func @lowered_affine_floordiv() -> (index, index) {
%c42 = constant 42 : index
%c0 = constant 0 : index
%c-1 = constant -1 : index
%0 = cmpi "slt", %c-43, %c0 : index
%0 = cmpi slt, %c-43, %c0 : index
%1 = subi %c-1, %c-43 : index
%2 = select %0, %1, %c-43 : index
%3 = divi_signed %2, %c42 : index
Expand All @@ -614,7 +614,7 @@ func @lowered_affine_floordiv() -> (index, index) {
%c42_0 = constant 42 : index
%c0_1 = constant 0 : index
%c-1_2 = constant -1 : index
%6 = cmpi "slt", %c43, %c0_1 : index
%6 = cmpi slt, %c43, %c0_1 : index
%7 = subi %c-1_2, %c43 : index
%8 = select %6, %7, %c43 : index
%9 = divi_signed %8, %c42_0 : index
Expand All @@ -635,7 +635,7 @@ func @lowered_affine_ceildiv() -> (index, index) {
%c42 = constant 42 : index
%c0 = constant 0 : index
%c1 = constant 1 : index
%0 = cmpi "sle", %c-43, %c0 : index
%0 = cmpi sle, %c-43, %c0 : index
%1 = subi %c0, %c-43 : index
%2 = subi %c-43, %c1 : index
%3 = select %0, %1, %2 : index
Expand All @@ -648,7 +648,7 @@ func @lowered_affine_ceildiv() -> (index, index) {
%c42_0 = constant 42 : index
%c0_1 = constant 0 : index
%c1_2 = constant 1 : index
%8 = cmpi "sle", %c43, %c0_1 : index
%8 = cmpi sle, %c43, %c0_1 : index
%9 = subi %c0_1, %c43 : index
%10 = subi %c43, %c1_2 : index
%11 = select %8, %9, %10 : index
Expand Down
116 changes: 58 additions & 58 deletions mlir/test/Transforms/constant-fold.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -563,25 +563,25 @@ func @cmpi() -> (i1, i1, i1, i1, i1, i1, i1, i1, i1, i1) {
// CHECK-DAG: [[F:%.+]] = constant false
// CHECK-DAG: [[T:%.+]] = constant true
// CHECK-NEXT: return [[F]],
%0 = cmpi "eq", %c42, %cm1 : i32
%0 = cmpi eq, %c42, %cm1 : i32
// CHECK-SAME: [[T]],
%1 = cmpi "ne", %c42, %cm1 : i32
%1 = cmpi ne, %c42, %cm1 : i32
// CHECK-SAME: [[F]],
%2 = cmpi "slt", %c42, %cm1 : i32
%2 = cmpi slt, %c42, %cm1 : i32
// CHECK-SAME: [[F]],
%3 = cmpi "sle", %c42, %cm1 : i32
%3 = cmpi sle, %c42, %cm1 : i32
// CHECK-SAME: [[T]],
%4 = cmpi "sgt", %c42, %cm1 : i32
%4 = cmpi sgt, %c42, %cm1 : i32
// CHECK-SAME: [[T]],
%5 = cmpi "sge", %c42, %cm1 : i32
%5 = cmpi sge, %c42, %cm1 : i32
// CHECK-SAME: [[T]],
%6 = cmpi "ult", %c42, %cm1 : i32
%6 = cmpi ult, %c42, %cm1 : i32
// CHECK-SAME: [[T]],
%7 = cmpi "ule", %c42, %cm1 : i32
%7 = cmpi ule, %c42, %cm1 : i32
// CHECK-SAME: [[F]],
%8 = cmpi "ugt", %c42, %cm1 : i32
%8 = cmpi ugt, %c42, %cm1 : i32
// CHECK-SAME: [[F]]
%9 = cmpi "uge", %c42, %cm1 : i32
%9 = cmpi uge, %c42, %cm1 : i32
return %0, %1, %2, %3, %4, %5, %6, %7, %8, %9 : i1, i1, i1, i1, i1, i1, i1, i1, i1, i1
}

Expand All @@ -594,37 +594,37 @@ func @cmpf_normal_numbers() -> (i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1,
// CHECK-DAG: [[F:%.+]] = constant false
// CHECK-DAG: [[T:%.+]] = constant true
// CHECK-NEXT: return [[F]],
%0 = cmpf "false", %c42, %cm1 : f32
%0 = cmpf false, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%1 = cmpf "oeq", %c42, %cm1 : f32
%1 = cmpf oeq, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%2 = cmpf "ogt", %c42, %cm1 : f32
%2 = cmpf ogt, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%3 = cmpf "oge", %c42, %cm1 : f32
%3 = cmpf oge, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%4 = cmpf "olt", %c42, %cm1 : f32
%4 = cmpf olt, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%5 = cmpf "ole", %c42, %cm1 : f32
%5 = cmpf ole, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%6 = cmpf "one", %c42, %cm1 : f32
%6 = cmpf one, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%7 = cmpf "ord", %c42, %cm1 : f32
%7 = cmpf ord, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%8 = cmpf "ueq", %c42, %cm1 : f32
%8 = cmpf ueq, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%9 = cmpf "ugt", %c42, %cm1 : f32
%9 = cmpf ugt, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%10 = cmpf "uge", %c42, %cm1 : f32
%10 = cmpf uge, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%11 = cmpf "ult", %c42, %cm1 : f32
%11 = cmpf ult, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%12 = cmpf "ule", %c42, %cm1 : f32
%12 = cmpf ule, %c42, %cm1 : f32
// CHECK-SAME: [[T]],
%13 = cmpf "une", %c42, %cm1 : f32
%13 = cmpf une, %c42, %cm1 : f32
// CHECK-SAME: [[F]],
%14 = cmpf "uno", %c42, %cm1 : f32
%14 = cmpf uno, %c42, %cm1 : f32
// CHECK-SAME: [[T]]
%15 = cmpf "true", %c42, %cm1 : f32
%15 = cmpf true, %c42, %cm1 : f32
return %0, %1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15 : i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1
}

Expand All @@ -637,37 +637,37 @@ func @cmpf_nan() -> (i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1,
// CHECK-DAG: [[F:%.+]] = constant false
// CHECK-DAG: [[T:%.+]] = constant true
// CHECK-NEXT: return [[F]],
%0 = cmpf "false", %c42, %cqnan : f32
%0 = cmpf false, %c42, %cqnan : f32
// CHECK-SAME: [[F]]
%1 = cmpf "oeq", %c42, %cqnan : f32
%1 = cmpf oeq, %c42, %cqnan : f32
// CHECK-SAME: [[F]],
%2 = cmpf "ogt", %c42, %cqnan : f32
%2 = cmpf ogt, %c42, %cqnan : f32
// CHECK-SAME: [[F]],
%3 = cmpf "oge", %c42, %cqnan : f32
%3 = cmpf oge, %c42, %cqnan : f32
// CHECK-SAME: [[F]],
%4 = cmpf "olt", %c42, %cqnan : f32
%4 = cmpf olt, %c42, %cqnan : f32
// CHECK-SAME: [[F]],
%5 = cmpf "ole", %c42, %cqnan : f32
%5 = cmpf ole, %c42, %cqnan : f32
// CHECK-SAME: [[F]],
%6 = cmpf "one", %c42, %cqnan : f32
%6 = cmpf one, %c42, %cqnan : f32
// CHECK-SAME: [[F]],
%7 = cmpf "ord", %c42, %cqnan : f32
%7 = cmpf ord, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%8 = cmpf "ueq", %c42, %cqnan : f32
%8 = cmpf ueq, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%9 = cmpf "ugt", %c42, %cqnan : f32
%9 = cmpf ugt, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%10 = cmpf "uge", %c42, %cqnan : f32
%10 = cmpf uge, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%11 = cmpf "ult", %c42, %cqnan : f32
%11 = cmpf ult, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%12 = cmpf "ule", %c42, %cqnan : f32
%12 = cmpf ule, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%13 = cmpf "une", %c42, %cqnan : f32
%13 = cmpf une, %c42, %cqnan : f32
// CHECK-SAME: [[T]],
%14 = cmpf "uno", %c42, %cqnan : f32
%14 = cmpf uno, %c42, %cqnan : f32
// CHECK-SAME: [[T]]
%15 = cmpf "true", %c42, %cqnan : f32
%15 = cmpf true, %c42, %cqnan : f32
return %0, %1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15 : i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1
}

Expand All @@ -680,37 +680,37 @@ func @cmpf_inf() -> (i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1,
// CHECK-DAG: [[F:%.+]] = constant false
// CHECK-DAG: [[T:%.+]] = constant true
// CHECK-NEXT: return [[F]],
%0 = cmpf "false", %c42, %cpinf: f32
%0 = cmpf false, %c42, %cpinf: f32
// CHECK-SAME: [[F]]
%1 = cmpf "oeq", %c42, %cpinf: f32
%1 = cmpf oeq, %c42, %cpinf: f32
// CHECK-SAME: [[F]],
%2 = cmpf "ogt", %c42, %cpinf: f32
%2 = cmpf ogt, %c42, %cpinf: f32
// CHECK-SAME: [[F]],
%3 = cmpf "oge", %c42, %cpinf: f32
%3 = cmpf oge, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%4 = cmpf "olt", %c42, %cpinf: f32
%4 = cmpf olt, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%5 = cmpf "ole", %c42, %cpinf: f32
%5 = cmpf ole, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%6 = cmpf "one", %c42, %cpinf: f32
%6 = cmpf one, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%7 = cmpf "ord", %c42, %cpinf: f32
%7 = cmpf ord, %c42, %cpinf: f32
// CHECK-SAME: [[F]],
%8 = cmpf "ueq", %c42, %cpinf: f32
%8 = cmpf ueq, %c42, %cpinf: f32
// CHECK-SAME: [[F]],
%9 = cmpf "ugt", %c42, %cpinf: f32
%9 = cmpf ugt, %c42, %cpinf: f32
// CHECK-SAME: [[F]],
%10 = cmpf "uge", %c42, %cpinf: f32
%10 = cmpf uge, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%11 = cmpf "ult", %c42, %cpinf: f32
%11 = cmpf ult, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%12 = cmpf "ule", %c42, %cpinf: f32
%12 = cmpf ule, %c42, %cpinf: f32
// CHECK-SAME: [[T]],
%13 = cmpf "une", %c42, %cpinf: f32
%13 = cmpf une, %c42, %cpinf: f32
// CHECK-SAME: [[F]],
%14 = cmpf "uno", %c42, %cpinf: f32
%14 = cmpf uno, %c42, %cpinf: f32
// CHECK-SAME: [[T]]
%15 = cmpf "true", %c42, %cpinf: f32
%15 = cmpf true, %c42, %cpinf: f32
return %0, %1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15 : i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i1
}

Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Transforms/copy-removal.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// CHECK-LABEL: func @nested_region_control_flow_div_nested
func @nested_region_control_flow_div_nested(%arg0: index, %arg1: index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
// CHECK: %{{.*}} = scf.if
%2 = scf.if %0 -> (memref<?x?xf32>) {
Expand Down Expand Up @@ -311,7 +311,7 @@ func @loop_alloc(%arg0: index, %arg1: index, %arg2: index, %arg3: memref<2xf32>,
// CHECK: linalg.copy
linalg.copy(%arg3, %1) : memref<2xf32>, memref<2xf32>
%2 = scf.for %arg5 = %arg0 to %arg1 step %arg2 iter_args(%arg6 = %1) -> (memref<2xf32>) {
%3 = cmpi "eq", %arg5, %arg1 : index
%3 = cmpi eq, %arg5, %arg1 : index
// CHECK: dealloc
dealloc %arg6 : memref<2xf32>
// CHECK: %[[PERCENT4:.*]] = alloc()
Expand Down Expand Up @@ -347,7 +347,7 @@ func @check_with_affine_dialect(%arg0: memref<4xf32>, %arg1: memref<4xf32>, %arg
affine.for %arg3 = 0 to 4 {
%5 = affine.load %arg0[%arg3] : memref<4xf32>
%6 = affine.load %arg1[%arg3] : memref<4xf32>
%7 = cmpf "ogt", %5, %6 : f32
%7 = cmpf ogt, %5, %6 : f32
// CHECK: %[[SELECT_RES:.*]] = select
%8 = select %7, %5, %6 : f32
// CHECK-NEXT: affine.store %[[SELECT_RES]], %[[RES]]
Expand Down
8 changes: 4 additions & 4 deletions mlir/test/Transforms/cse.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func @different_results(%arg0: tensor<*xf32>) -> (tensor<?x?xf32>, tensor<4x?xf3
// CHECK-LABEL: @different_attributes
func @different_attributes(index, index) -> (i1, i1, i1) {
^bb0(%a : index, %b : index):
// CHECK: %0 = cmpi "slt", %arg0, %arg1 : index
%0 = cmpi "slt", %a, %b : index
// CHECK: %0 = cmpi slt, %arg0, %arg1 : index
%0 = cmpi slt, %a, %b : index

// CHECK-NEXT: %1 = cmpi "ne", %arg0, %arg1 : index
// CHECK-NEXT: %1 = cmpi ne, %arg0, %arg1 : index
/// Predicate 1 means inequality comparison.
%1 = cmpi "ne", %a, %b : index
%1 = cmpi ne, %a, %b : index
%2 = "std.cmpi"(%a, %b) {predicate = 1} : (index, index) -> i1

// CHECK-NEXT: return %0, %1, %1 : i1, i1, i1
Expand Down
8 changes: 4 additions & 4 deletions mlir/test/Transforms/parametric-tiling.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func @rectangular(%arg0: memref<?x?xf32>) {
scf.for %i = %c2 to %c44 step %c1 {
// Upper bound for the inner loop min(%i + %step, %c44).
// COMMON: %[[stepped:.*]] = addi %[[i]], %[[step]]
// COMMON-NEXT: cmpi "slt", %c44, %[[stepped]]
// COMMON-NEXT: cmpi slt, %c44, %[[stepped]]
// COMMON-NEXT: %[[ub:.*]] = select {{.*}}, %c44, %[[stepped]]
//
// TILE_74: %[[stepped2:.*]] = addi %[[j]], %[[step2]]
// TILE_74-NEXT: cmpi "slt", %c44, %[[stepped2]]
// TILE_74-NEXT: cmpi slt, %c44, %[[stepped2]]
// TILE_74-NEXT: %[[ub2:.*]] = select {{.*}}, %c44, %[[stepped2]]

// Created inner scf.
Expand Down Expand Up @@ -108,10 +108,10 @@ func @triangular(%arg0: memref<?x?xf32>) {
scf.for %i = %c2 to %c44 step %c1 {
// Upper bound for the inner loop min(%i + %step, %c44).
// COMMON: %[[stepped:.*]] = addi %[[i]], %[[step]]
// COMMON-NEXT: cmpi "slt", %c44, %[[stepped]]
// COMMON-NEXT: cmpi slt, %c44, %[[stepped]]
// COMMON-NEXT: %[[ub:.*]] = select {{.*}}, %c44, %[[stepped]]
// TILE_74: %[[stepped2:.*]] = addi %[[j]], %[[step2]]
// TILE_74-NEXT: cmpi "slt", %[[i]], %[[stepped2]]
// TILE_74-NEXT: cmpi slt, %[[i]], %[[stepped2]]
// TILE_74-NEXT: %[[ub2:.*]] = select {{.*}}, %[[i]], %[[stepped2]]
//
// Created inner scf.
Expand Down
8 changes: 4 additions & 4 deletions mlir/test/Transforms/promote-buffers-to-stack.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func @memref_in_function_results(
func @nested_region_control_flow(
%arg0 : index,
%arg1 : index) -> memref<?x?xf32> {
%0 = cmpi "eq", %arg0, %arg1 : index
%0 = cmpi eq, %arg0, %arg1 : index
%1 = alloc(%arg0, %arg0) : memref<?x?xf32>
%2 = scf.if %0 -> (memref<?x?xf32>) {
scf.yield %1 : memref<?x?xf32>
Expand Down Expand Up @@ -482,7 +482,7 @@ func @loop_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = alloc() : memref<2xf32>
scf.yield %3 : memref<2xf32>
}
Expand Down Expand Up @@ -512,7 +512,7 @@ func @loop_nested_if_no_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = scf.if %2 -> (memref<2xf32>) {
scf.yield %0 : memref<2xf32>
} else {
Expand Down Expand Up @@ -547,7 +547,7 @@ func @loop_nested_if_alloc(
%0 = alloc() : memref<2xf32>
%1 = scf.for %i = %lb to %ub step %step
iter_args(%iterBuf = %buf) -> memref<2xf32> {
%2 = cmpi "eq", %i, %ub : index
%2 = cmpi eq, %i, %ub : index
%3 = scf.if %2 -> (memref<2xf32>) {
%4 = alloc() : memref<2xf32>
scf.yield %4 : memref<2xf32>
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Transforms/sccp-callgraph.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func private @complex_inner_if(%arg0 : i32) -> i32 {
// CHECK: cond_br %[[TRUE]], ^bb1

%cst_20 = constant 20 : i32
%cond = cmpi "ult", %arg0, %cst_20 : i32
%cond = cmpi ult, %arg0, %cst_20 : i32
cond_br %cond, ^bb1, ^bb2

^bb1:
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Transforms/sccp-structured.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func @loop_inner_control_flow(%arg0 : index, %arg1 : index, %arg2 : index) -> i3
%cst_1 = constant 1 : i32
%result = scf.for %i0 = %arg0 to %arg1 step %arg2 iter_args(%si = %cst_1) -> (i32) {
%cst_20 = constant 20 : i32
%cond = cmpi "ult", %si, %cst_20 : i32
%cond = cmpi ult, %si, %cst_20 : i32
%inner_res = scf.if %cond -> (i32) {
%1 = constant 1 : i32
scf.yield %1 : i32
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Transforms/sccp.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func @simple_loop_inner_control_flow(%arg0 : i32) -> i32 {
// CHECK: cond_br %[[TRUE]], ^bb3, ^bb4

%cst_20 = constant 20 : i32
%cond = cmpi "ult", %iv, %cst_20 : i32
%cond = cmpi ult, %iv, %cst_20 : i32
cond_br %cond, ^bb3, ^bb4

^bb3:
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/mlir-tblgen/op-format.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ test.format_optional_unit_attribute
// CHECK: test.format_optional_unit_attribute_no_elide unit
test.format_optional_unit_attribute_no_elide unit

// CHECK: test.format_optional_enum_attr "case5"
test.format_optional_enum_attr "case5"
// CHECK: test.format_optional_enum_attr case5
test.format_optional_enum_attr case5

// CHECK: test.format_optional_enum_attr
// CHECK-NOT: "case5"
Expand Down
224 changes: 164 additions & 60 deletions mlir/tools/mlir-tblgen/OpFormatGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ static llvm::cl::opt<bool> formatErrorIsFatal(
llvm::cl::desc("Emit a fatal error if format parsing fails"),
llvm::cl::init(true));

/// Returns true if the given string can be formatted as a keyword.
static bool canFormatStringAsKeyword(StringRef value) {
if (!isalpha(value.front()) && value.front() != '_')
return false;
return llvm::all_of(value.drop_front(), [](char c) {
return isalnum(c) || c == '_' || c == '$' || c == '.';
});
}

//===----------------------------------------------------------------------===//
// Element
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -289,11 +298,7 @@ bool LiteralElement::isValidLiteral(StringRef value) {
return true;

// Otherwise, this must be an identifier.
if (!isalpha(front) && front != '_')
return false;
return llvm::all_of(value.drop_front(), [](char c) {
return isalnum(c) || c == '_' || c == '$' || c == '.';
});
return canFormatStringAsKeyword(value);
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -536,41 +541,32 @@ const char *const optionalSymbolNameAttrParserCode = R"(
/// {1}: The c++ namespace for the enum symbolize functions.
/// {2}: The function to symbolize a string of the enum.
/// {3}: The constant builder call to create an attribute of the enum type.
/// {4}: The set of allowed enum keywords.
/// {5}: The error message on failure when the enum isn't present.
const char *const enumAttrParserCode = R"(
{
::mlir::StringAttr attrVal;
::llvm::StringRef attrStr;
::mlir::NamedAttrList attrStorage;
auto loc = parser.getCurrentLocation();
if (parser.parseAttribute(attrVal, parser.getBuilder().getNoneType(),
"{0}", attrStorage))
return ::mlir::failure();
auto attrOptional = {1}::{2}(attrVal.getValue());
if (!attrOptional)
return parser.emitError(loc, "invalid ")
<< "{0} attribute specification: " << attrVal;
{0}Attr = {3};
result.addAttribute("{0}", {0}Attr);
}
)";
const char *const optionalEnumAttrParserCode = R"(
{
::mlir::StringAttr attrVal;
::mlir::NamedAttrList attrStorage;
auto loc = parser.getCurrentLocation();
::mlir::OptionalParseResult parseResult =
parser.parseOptionalAttribute(attrVal, parser.getBuilder().getNoneType(),
"{0}", attrStorage);
if (parseResult.hasValue()) {
if (failed(*parseResult))
return ::mlir::failure();
auto attrOptional = {1}::{2}(attrVal.getValue());
if (parser.parseOptionalKeyword(&attrStr, {4})) {
::mlir::StringAttr attrVal;
::mlir::OptionalParseResult parseResult =
parser.parseOptionalAttribute(attrVal,
parser.getBuilder().getNoneType(),
"{0}", attrStorage);
if (parseResult.hasValue()) {{
if (failed(*parseResult))
return ::mlir::failure();
attrStr = attrVal.getValue();
} else {
{5}
}
}
if (!attrStr.empty()) {
auto attrOptional = {1}::{2}(attrStr);
if (!attrOptional)
return parser.emitError(loc, "invalid ")
<< "{0} attribute specification: " << attrVal;
<< "{0} attribute specification: \"" << attrStr << '"';;
{0}Attr = {3};
result.addAttribute("{0}", {0}Attr);
Expand Down Expand Up @@ -1029,6 +1025,49 @@ static void genCustomDirectiveParser(CustomDirective *dir, OpMethodBody &body) {
body << " }\n";
}

/// Generate the parser for a enum attribute.
static void genEnumAttrParser(const NamedAttribute *var, OpMethodBody &body,
FmtContext &attrTypeCtx) {
Attribute baseAttr = var->attr.getBaseAttr();
const EnumAttr &enumAttr = cast<EnumAttr>(baseAttr);
std::vector<EnumAttrCase> cases = enumAttr.getAllCases();

// Generate the code for building an attribute for this enum.
std::string attrBuilderStr;
{
llvm::raw_string_ostream os(attrBuilderStr);
os << tgfmt(enumAttr.getConstBuilderTemplate(), &attrTypeCtx,
"attrOptional.getValue()");
}

// Build a string containing the cases that can be formatted as a keyword.
std::string validCaseKeywordsStr = "{";
llvm::raw_string_ostream validCaseKeywordsOS(validCaseKeywordsStr);
for (const EnumAttrCase &attrCase : cases)
if (canFormatStringAsKeyword(attrCase.getStr()))
validCaseKeywordsOS << '"' << attrCase.getStr() << "\",";
validCaseKeywordsOS.str().back() = '}';

// If the attribute is not optional, build an error message for the missing
// attribute.
std::string errorMessage;
if (!var->attr.isOptional()) {
llvm::raw_string_ostream errorMessageOS(errorMessage);
errorMessageOS
<< "return parser.emitError(loc, \"expected string or "
"keyword containing one of the following enum values for attribute '"
<< var->name << "' [";
llvm::interleaveComma(cases, errorMessageOS, [&](const auto &attrCase) {
errorMessageOS << attrCase.getStr();
});
errorMessageOS << "]\");";
}

body << formatv(enumAttrParserCode, var->name, enumAttr.getCppNamespace(),
enumAttr.getStringToSymbolFnName(), attrBuilderStr,
validCaseKeywordsStr, errorMessage);
}

void OperationFormat::genParser(Operator &op, OpClass &opClass) {
llvm::SmallVector<OpMethodParameter, 4> paramList;
paramList.emplace_back("::mlir::OpAsmParser &", "parser");
Expand Down Expand Up @@ -1130,24 +1169,8 @@ void OperationFormat::genElementParser(Element *element, OpMethodBody &body,
const NamedAttribute *var = attr->getVar();

// Check to see if we can parse this as an enum attribute.
if (canFormatEnumAttr(var)) {
Attribute baseAttr = var->attr.getBaseAttr();
const EnumAttr &enumAttr = cast<EnumAttr>(baseAttr);

// Generate the code for building an attribute for this enum.
std::string attrBuilderStr;
{
llvm::raw_string_ostream os(attrBuilderStr);
os << tgfmt(enumAttr.getConstBuilderTemplate(), &attrTypeCtx,
"attrOptional.getValue()");
}

body << formatv(var->attr.isOptional() ? optionalEnumAttrParserCode
: enumAttrParserCode,
var->name, enumAttr.getCppNamespace(),
enumAttr.getStringToSymbolFnName(), attrBuilderStr);
return;
}
if (canFormatEnumAttr(var))
return genEnumAttrParser(var, body, attrTypeCtx);

// Check to see if we should parse this as a symbol name attribute.
if (shouldFormatSymbolNameAttr(var)) {
Expand Down Expand Up @@ -1497,6 +1520,17 @@ const char *regionSingleBlockImplicitTerminatorPrinterCode = R"(
}
)";

/// The code snippet used to generate a printer call for an enum that has cases
/// that can't be represented with a keyword.
///
/// {0}: The name of the enum attribute.
/// {1}: The name of the enum attributes symbolToString function.
const char *enumAttrBeginPrinterCode = R"(
{
auto caseValue = {0}();
auto caseValueStr = {1}(caseValue);
)";

/// Generate the printer for the 'attr-dict' directive.
static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
OpMethodBody &body, bool withKeyword) {
Expand Down Expand Up @@ -1639,6 +1673,82 @@ static OpMethodBody &genTypeOperandPrinter(Element *arg, OpMethodBody &body) {
<< "().getType())";
}

/// Generate the printer for an enum attribute.
static void genEnumAttrPrinter(const NamedAttribute *var, OpMethodBody &body) {
Attribute baseAttr = var->attr.getBaseAttr();
const EnumAttr &enumAttr = cast<EnumAttr>(baseAttr);
std::vector<EnumAttrCase> cases = enumAttr.getAllCases();

body << llvm::formatv(enumAttrBeginPrinterCode,
(var->attr.isOptional() ? "*" : "") + var->name,
enumAttr.getSymbolToStringFnName());

// Get a string containing all of the cases that can't be represented with a
// keyword.
llvm::BitVector nonKeywordCases(cases.size());
bool hasStrCase = false;
for (auto it : llvm::enumerate(cases)) {
hasStrCase = it.value().isStrCase();
if (!canFormatStringAsKeyword(it.value().getStr()))
nonKeywordCases.set(it.index());
}

// If this is a string enum, use the case string to determine which cases
// need to use the string form.
if (hasStrCase) {
if (nonKeywordCases.any()) {
body << " if (llvm::is_contained(llvm::ArrayRef<llvm::StringRef>(";
llvm::interleaveComma(nonKeywordCases.set_bits(), body, [&](unsigned it) {
body << '"' << cases[it].getStr() << '"';
});
body << ")))\n"
" p << '\"' << caseValueStr << '\"';\n"
" else\n ";
}
body << " p << caseValueStr;\n"
" }\n";
return;
}

// Otherwise if this is a bit enum attribute, don't allow cases that may
// overlap with other cases. For simplicity sake, only allow cases with a
// single bit value.
if (enumAttr.isBitEnum()) {
for (auto it : llvm::enumerate(cases)) {
int64_t value = it.value().getValue();
if (value < 0 || !llvm::isPowerOf2_64(value))
nonKeywordCases.set(it.index());
}
}

// If there are any cases that can't be used with a keyword, switch on the
// case value to determine when to print in the string form.
if (nonKeywordCases.any()) {
body << " switch (caseValue) {\n";
StringRef cppNamespace = enumAttr.getCppNamespace();
StringRef enumName = enumAttr.getEnumClassName();
for (auto it : llvm::enumerate(cases)) {
if (nonKeywordCases.test(it.index()))
continue;
StringRef symbol = it.value().getSymbol();
body << llvm::formatv(" case {0}::{1}::{2}:\n", cppNamespace, enumName,
llvm::isDigit(symbol.front()) ? ("_" + symbol)
: symbol);
}
body << " p << caseValueStr;\n"
" break;\n"
" default:\n"
" p << '\"' << caseValueStr << '\"';\n"
" break;\n"
" }\n"
" }\n";
return;
}

body << " p << caseValueStr;\n"
" }\n";
}

void OperationFormat::genElementPrinter(Element *element, OpMethodBody &body,
Operator &op, bool &shouldEmitSpace,
bool &lastWasPunctuation) {
Expand Down Expand Up @@ -1714,14 +1824,8 @@ void OperationFormat::genElementPrinter(Element *element, OpMethodBody &body,
const NamedAttribute *var = attr->getVar();

// If we are formatting as an enum, symbolize the attribute as a string.
if (canFormatEnumAttr(var)) {
Attribute baseAttr = var->attr.getBaseAttr();
const EnumAttr &enumAttr = cast<EnumAttr>(baseAttr);
body << " p << '\"' << " << enumAttr.getSymbolToStringFnName() << "("
<< (var->attr.isOptional() ? "*" : "") << var->name
<< "()) << '\"';\n";
return;
}
if (canFormatEnumAttr(var))
return genEnumAttrPrinter(var, body);

// If we are formatting as a symbol name, handle it as a symbol name.
if (shouldFormatSymbolNameAttr(var)) {
Expand Down