<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/124086>124086</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir][emitc] Missing parentheses when translate emitc.expression
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir,
            mlir:emitc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            jacquesguan
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jacquesguan
      </td>
    </tr>
</table>

<pre>
    In some case, translation generates wrong cpp code for `emitc.expression`.

By example, the following case in `mlir/test/Target/Cpp/expressions.mlir`
```
func.func @parentheses_for_low_precedence(%arg0: i32, %arg1: i32, %arg2: i32) -> f32 {
  %e = emitc.expression : f32 {
    %a = emitc.add %arg0, %arg1 : (i32, i32) -> i32
    %b = emitc.mul %a, %arg2 : (i32, i32) -> i32
    %d = emitc.cast %b : i32 to f32
    emitc.yield %d : f32
  }
  return %e : f32
}
```
It will be translate to
```
float parentheses_for_low_precedence(int32_t v1, int32_t v2, int32_t v3) {
 return (float) (v1 + v2 * v3);
}
```
which misses the parentheses rounding the addition.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVMuO6zYM_Rp6Q0wgU7GdLLxwbhrgLrrrfqDYjK0LWXIlOZn5-0LOY9xpgRYwrAd5Dl8iVQi6t8w1FAcg-qXaP2cO_awsEEFxzNQcB-frlSA7u-6z_mkxuJGxVYGBfmD0ygajonYWe7bsVeSAN-9sj-00Yes6xovzCKXgUcd2wx-T5xC0s1CKDYgGRHP4RP5Q42TunEOCGONuOrGowKhtIhiN9kCnyCECnf5Qvue0-TFNQKcv3rBZFEuRyEvx-ERzmW27ST-ErZiUZxsHDhzeL86_G3d7nzy33LFtGWgHVCjfC5ANaknJr_tN_o8bet3s8Q3kb3iRhFAdQDSYVBhBHvF79JhQa81FV610Vdfh04sv8wsOaPdwYW037V9M5xXTOJsFvvL5_9J0K5pWhfikXiLG6FIID-270qdm0z2RzUsM1XFZPcfZ22danvK7dF2snxFv2hg88-uNMUb3vaTGqYj_WUtto6T3iNd8ifV5or-dZErAoxgvL3eLhUVCu2uOQAe8EgI1dwDIw7-6fxt0O-CoQ-CwPOiVj-jdbLv0tpNAdZ1O7ZNaIetq2e3lXmVc55Wsynwvt2U21OVOkuK8qCQpub-0JW87FudWMee5vHSZrklQIXKSYieIys12X3EpuqoSRXXZ7wVsBY9Km40x13HjfJ_pEGauc9qKXZkZdWYTHuPg3mcpO8-DbJbiPoaDrxPJ23nuA2yF0SGGL9qoo1nmygIsjlAc7tjiiL_rEFLc62TcBrarEn9vk2z2ph5inALIBugEdOp1HObzpnUj0CnZfSxvk3e_uE0jYYktAJ0e4V1r-isAAP__ZGl7KA">