[Mlir-commits] [mlir] 9c4825c - [mlir] do not use llvm.cmpxchg with floats
Alex Zinenko
llvmlistbot at llvm.org
Mon Aug 17 06:44:31 PDT 2020
Author: Alex Zinenko
Date: 2020-08-17T15:44:23+02:00
New Revision: 9c4825ce282d30ea108e6371c15cb692060ff4f3
URL: https://github.com/llvm/llvm-project/commit/9c4825ce282d30ea108e6371c15cb692060ff4f3
DIFF: https://github.com/llvm/llvm-project/commit/9c4825ce282d30ea108e6371c15cb692060ff4f3.diff
LOG: [mlir] do not use llvm.cmpxchg with floats
According to the LLVM Language Reference, 'cmpxchg' accepts integer or pointer
types. Several MLIR tests were using it with floats as it appears possible to
programmatically construct and print such an instruction, but it cannot be
parsed back. Use integers instead.
Depends On D85899
Reviewed By: flaub, rriddle
Differential Revision: https://reviews.llvm.org/D85900
Added:
Modified:
mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir
mlir/test/Dialect/LLVMIR/invalid.mlir
mlir/test/Dialect/LLVMIR/roundtrip.mlir
mlir/test/Target/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir b/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir
index e7935bc165f9..419ee17d8f06 100644
--- a/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir
+++ b/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir
@@ -1216,27 +1216,27 @@ func @atomic_rmw(%I : memref<10xi32>, %ival : i32, %F : memref<10xf32>, %fval :
// -----
// CHECK-LABEL: func @generic_atomic_rmw
-func @generic_atomic_rmw(%I : memref<10xf32>, %i : index) -> f32 {
- %x = generic_atomic_rmw %I[%i] : memref<10xf32> {
- ^bb0(%old_value : f32):
- %c1 = constant 1.0 : f32
- atomic_yield %c1 : f32
+func @generic_atomic_rmw(%I : memref<10xi32>, %i : index) -> i32 {
+ %x = generic_atomic_rmw %I[%i] : memref<10xi32> {
+ ^bb0(%old_value : i32):
+ %c1 = constant 1 : i32
+ atomic_yield %c1 : i32
}
- // CHECK: [[init:%.*]] = llvm.load %{{.*}} : !llvm.ptr<float>
- // CHECK-NEXT: llvm.br ^bb1([[init]] : !llvm.float)
- // CHECK-NEXT: ^bb1([[loaded:%.*]]: !llvm.float):
- // CHECK-NEXT: [[c1:%.*]] = llvm.mlir.constant(1.000000e+00 : f32)
+ // CHECK: [[init:%.*]] = llvm.load %{{.*}} : !llvm.ptr<i32>
+ // CHECK-NEXT: llvm.br ^bb1([[init]] : !llvm.i32)
+ // CHECK-NEXT: ^bb1([[loaded:%.*]]: !llvm.i32):
+ // CHECK-NEXT: [[c1:%.*]] = llvm.mlir.constant(1 : i32)
// CHECK-NEXT: [[pair:%.*]] = llvm.cmpxchg %{{.*}}, [[loaded]], [[c1]]
- // CHECK-SAME: acq_rel monotonic : !llvm.float
+ // CHECK-SAME: acq_rel monotonic : !llvm.i32
// CHECK-NEXT: [[new:%.*]] = llvm.extractvalue [[pair]][0]
// CHECK-NEXT: [[ok:%.*]] = llvm.extractvalue [[pair]][1]
- // CHECK-NEXT: llvm.cond_br [[ok]], ^bb2, ^bb1([[new]] : !llvm.float)
+ // CHECK-NEXT: llvm.cond_br [[ok]], ^bb2, ^bb1([[new]] : !llvm.i32)
// CHECK-NEXT: ^bb2:
- %c2 = constant 2.0 : f32
- %add = addf %c2, %x : f32
- return %add : f32
- // CHECK-NEXT: [[c2:%.*]] = llvm.mlir.constant(2.000000e+00 : f32)
- // CHECK-NEXT: [[add:%.*]] = llvm.fadd [[c2]], [[new]] : !llvm.float
+ %c2 = constant 2 : i32
+ %add = addi %c2, %x : i32
+ return %add : i32
+ // CHECK-NEXT: [[c2:%.*]] = llvm.mlir.constant(2 : i32)
+ // CHECK-NEXT: [[add:%.*]] = llvm.add [[c2]], [[new]] : !llvm.i32
// CHECK-NEXT: llvm.return [[add]]
}
diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 737fa4ff8bf1..4260d8a053e1 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -463,9 +463,9 @@ func @cmpxchg_expected_ptr(%f32_ptr : !llvm.ptr<float>, %f32 : !llvm.float) {
// -----
// CHECK-LABEL: @cmpxchg_mismatched_operands
-func @cmpxchg_mismatched_operands(%f32_ptr : !llvm.ptr<float>, %i32 : !llvm.i32) {
+func @cmpxchg_mismatched_operands(%i64_ptr : !llvm.ptr<i64>, %i32 : !llvm.i32) {
// expected-error at +1 {{expected LLVM IR element type for operand #0 to match type for all other operands}}
- %0 = "llvm.cmpxchg"(%f32_ptr, %i32, %i32) {success_ordering=2,failure_ordering=2} : (!llvm.ptr<float>, !llvm.i32, !llvm.i32) -> !llvm.struct<(i32, i1)>
+ %0 = "llvm.cmpxchg"(%i64_ptr, %i32, %i32) {success_ordering=2,failure_ordering=2} : (!llvm.ptr<i64>, !llvm.i32, !llvm.i32) -> !llvm.struct<(i32, i1)>
llvm.return
}
diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index ef89d76387d7..6d5e07602316 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -256,9 +256,9 @@ func @atomicrmw(%ptr : !llvm.ptr<float>, %val : !llvm.float) {
}
// CHECK-LABEL: @cmpxchg
-func @cmpxchg(%ptr : !llvm.ptr<float>, %cmp : !llvm.float, %new : !llvm.float) {
- // CHECK: llvm.cmpxchg %{{.*}}, %{{.*}}, %{{.*}} acq_rel monotonic : !llvm.float
- %0 = llvm.cmpxchg %ptr, %cmp, %new acq_rel monotonic : !llvm.float
+func @cmpxchg(%ptr : !llvm.ptr<i32>, %cmp : !llvm.i32, %new : !llvm.i32) {
+ // CHECK: llvm.cmpxchg %{{.*}}, %{{.*}}, %{{.*}} acq_rel monotonic : !llvm.i32
+ %0 = llvm.cmpxchg %ptr, %cmp, %new acq_rel monotonic : !llvm.i32
llvm.return
}
diff --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir
index b1abae64a2ad..24add42289ae 100644
--- a/mlir/test/Target/llvmir.mlir
+++ b/mlir/test/Target/llvmir.mlir
@@ -1139,13 +1139,13 @@ llvm.func @atomicrmw(
}
// CHECK-LABEL: @cmpxchg
-llvm.func @cmpxchg(%ptr : !llvm.ptr<float>, %cmp : !llvm.float, %val: !llvm.float) {
- // CHECK: cmpxchg float* %{{.*}}, float %{{.*}}, float %{{.*}} acq_rel monotonic
- %0 = llvm.cmpxchg %ptr, %cmp, %val acq_rel monotonic : !llvm.float
- // CHECK: %{{[0-9]+}} = extractvalue { float, i1 } %{{[0-9]+}}, 0
- %1 = llvm.extractvalue %0[0] : !llvm.struct<(float, i1)>
- // CHECK: %{{[0-9]+}} = extractvalue { float, i1 } %{{[0-9]+}}, 1
- %2 = llvm.extractvalue %0[1] : !llvm.struct<(float, i1)>
+llvm.func @cmpxchg(%ptr : !llvm.ptr<i32>, %cmp : !llvm.i32, %val: !llvm.i32) {
+ // CHECK: cmpxchg i32* %{{.*}}, i32 %{{.*}}, i32 %{{.*}} acq_rel monotonic
+ %0 = llvm.cmpxchg %ptr, %cmp, %val acq_rel monotonic : !llvm.i32
+ // CHECK: %{{[0-9]+}} = extractvalue { i32, i1 } %{{[0-9]+}}, 0
+ %1 = llvm.extractvalue %0[0] : !llvm.struct<(i32, i1)>
+ // CHECK: %{{[0-9]+}} = extractvalue { i32, i1 } %{{[0-9]+}}, 1
+ %2 = llvm.extractvalue %0[1] : !llvm.struct<(i32, i1)>
llvm.return
}
More information about the Mlir-commits
mailing list