<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62341>62341</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect Output in Canonicalize Transformation for clamp_float_is_noop Unit Test in canonicalize.mlir
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wyanzhao
</td>
</tr>
</table>
<pre>
I found an issue with the canonicalize transformation in the LLVM MLIR project, specifically in the `clamp_float_is_noop` unit test within `canonicalize.mlir`.
Input code:
```
Input code:
// CHECK-LABEL: @clamp_float_is_noop
func.func @clamp_float_is_noop(%arg0: tensor<4xf32>) -> tensor<4xf32> {
// CHECK: return %arg0
// CHECK-NOT: "tosa.clamp"
%0 = "tosa.clamp"(%arg0) {min_int = -128 : i64, max_int = 127 : i64, min_fp = -3.40282347E+38 : f32, max_fp = 3.40282347E+38 : f32} : (tensor<4xf32>) -> tensor<4xf32>
return %0 : tensor<4xf32>
}
```
Output code after running `mlir-opt -canonicalize="test-convergence"`:
```
func.func @clamp_float_is_noop(%arg0: tensor<4xf32>) -> tensor<4xf32> {
return %arg0 : tensor<4xf32>
}
```
The issue arises when the input tensor `arg0` has the following values:
```
arg0 (tensor<4xf32>): (dim: 4) (0) -> -Inf, (1) -> -Inf, (2) -> -Inf, (3) -> -Inf
```
In this case, the original code outputs `-3.40282347E+38`, while the canonicalized code outputs `-Inf`. These two values are not equivalent, indicating that the canonicalize transformation produced an incorrect result for special values.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VV2P6yYQ_TX4ZWSLgOM4D37YzYcaNbdXqtK-RsQex1QEUsCbu_vrK7D3I0qiqn24UkQsODPMORwG4Zw8asSKTJ_JdJmI3nfGVpdXod86YZKDaV6rDbSm1w0IDdK5HuEifQe-Q6iFNlrWQsk3BG-Fdq2xJ-Gl0SB1hGy3f36Db9v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