[Mlir-commits] [mlir] [mlir][emitc] Fix corner case in translation of literal ops (PR #71375)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Nov 6 02:57:31 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Simon Camphausen (simon-camp)

<details>
<summary>Changes</summary>

Fix a corner case missed in #<!-- -->71296 when operands generated by literals are mixed with the args attribute of a call op. Additionally remove a range check that is already done by the CallOp verifier.

---
Full diff: https://github.com/llvm/llvm-project/pull/71375.diff


2 Files Affected:

- (modified) mlir/lib/Target/Cpp/TranslateToCpp.cpp (-5) 
- (modified) mlir/test/Target/Cpp/literal_call_operand.mlir (+12) 


``````````diff
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 6c95eb3d20dacde..eeec9b11af7a0d0 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -425,11 +425,6 @@ static LogicalResult printOperation(CppEmitter &emitter, emitc::CallOp callOp) {
       // Index attributes are treated specially as operand index.
       if (t.getType().isIndex()) {
         int64_t idx = t.getInt();
-        if ((idx < 0) || (idx >= op.getNumOperands()))
-          return op.emitOpError("invalid operand index");
-        if (!emitter.hasValueInScope(op.getOperand(idx)))
-          return op.emitOpError("operand ")
-                 << idx << "'s value not defined in scope";
         os << emitter.getOrCreateName(op.getOperand(idx));
         return success();
       }
diff --git a/mlir/test/Target/Cpp/literal_call_operand.mlir b/mlir/test/Target/Cpp/literal_call_operand.mlir
index 017b4d53c43e3d8..428b66bb2519d9c 100644
--- a/mlir/test/Target/Cpp/literal_call_operand.mlir
+++ b/mlir/test/Target/Cpp/literal_call_operand.mlir
@@ -12,3 +12,15 @@ func.func @emitc_call_operand() {
 // CPP-DECLTOP: void emitc_call_operand() {
 // CPP-DECLTOP-NEXT: float v1;
 // CPP-DECLTOP-NEXT: v1 = foo(M_PI);
+
+func.func @emitc_call_operand_arg() {
+  %p0 = emitc.literal "M_PI" : f32
+  %1 = emitc.call "bar"(%p0) {args = [42 : i32, 0 : index]} : (f32) -> f32
+  return
+}
+// CPP-DEFAULT: void emitc_call_operand_arg() {
+// CPP-DEFAULT-NEXT: float v1 = bar(42, M_PI);
+
+// CPP-DECLTOP: void emitc_call_operand_arg() {
+// CPP-DECLTOP-NEXT: float v1;
+// CPP-DECLTOP-NEXT: v1 = bar(42, M_PI);

``````````

</details>


https://github.com/llvm/llvm-project/pull/71375


More information about the Mlir-commits mailing list