diff mbox series

[v4,46/51] tcg/optimize: Use fold_xx_to_i for rem

Message ID 20211026230943.1225890-47-richard.henderson@linaro.org
State New
Headers show
Series tcg: optimize redundant sign extensions | expand

Commit Message

Richard Henderson Oct. 26, 2021, 11:09 p.m. UTC
Recognize the constant function for remainder.

Suggested-by: Luis Pires <luis.pires@eldorado.org.br>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/optimize.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Oct. 27, 2021, 1:51 p.m. UTC | #1
On 10/27/21 01:09, Richard Henderson wrote:
> Recognize the constant function for remainder.
> 
> Suggested-by: Luis Pires <luis.pires@eldorado.org.br>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  tcg/optimize.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Luis Fernando Fujita Pires Oct. 27, 2021, 8:42 p.m. UTC | #2
From: Richard Henderson <richard.henderson@linaro.org>

>  static bool fold_remainder(OptContext *ctx, TCGOp *op)  {
> -    return fold_const2(ctx, op);
> +    if (fold_const2(ctx, op) ||
> +        fold_xx_to_i(ctx, op, 1)) {

Should this be fold_xx_to_i(ctx, op, 0)?
If arg[2] is 0, we would have different results than do_constant_folding(), but not sure we care, since the result is documented as undefined.

--
Luis Pires
Instituto de Pesquisas ELDORADO
Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>
Richard Henderson Oct. 28, 2021, 12:08 a.m. UTC | #3
On 10/27/21 1:42 PM, Luis Fernando Fujita Pires wrote:
> From: Richard Henderson <richard.henderson@linaro.org>
> 
>>   static bool fold_remainder(OptContext *ctx, TCGOp *op)  {
>> -    return fold_const2(ctx, op);
>> +    if (fold_const2(ctx, op) ||
>> +        fold_xx_to_i(ctx, op, 1)) {
> 
> Should this be fold_xx_to_i(ctx, op, 0)?

Oops.  I can only guess it's a cut-and-paste error.

> If arg[2] is 0, we would have different results than do_constant_folding(), but not sure we care, since the result is documented as undefined.

At first I thought you meant a known 0, but you mean some unknown value which happens to 
be 0 at runtime.  Yes, we do get a different value, but yes, we don't care because undefined.


r~
diff mbox series

Patch

diff --git a/tcg/optimize.c b/tcg/optimize.c
index 92684d4b1d..6c6c523a85 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1623,7 +1623,11 @@  static bool fold_qemu_st(OptContext *ctx, TCGOp *op)
 
 static bool fold_remainder(OptContext *ctx, TCGOp *op)
 {
-    return fold_const2(ctx, op);
+    if (fold_const2(ctx, op) ||
+        fold_xx_to_i(ctx, op, 1)) {
+        return true;
+    }
+    return false;
 }
 
 static bool fold_setcond(OptContext *ctx, TCGOp *op)