llvm-project
llvm-project copied to clipboard
[mlir][emitc] Missing parentheses when translate emitc.expression
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.
@llvm/issue-subscribers-mlir
Author: Jianjian Guan (jacquesguan)
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.