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

Richard Henderson posted 51 patches 4 years, 3 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>
[PATCH v4 46/51] tcg/optimize: Use fold_xx_to_i for rem
Posted by Richard Henderson 4 years, 3 months ago
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(-)

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)
-- 
2.25.1


Re: [PATCH v4 46/51] tcg/optimize: Use fold_xx_to_i for rem
Posted by Philippe Mathieu-Daudé 4 years, 3 months ago
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>

RE: [PATCH v4 46/51] tcg/optimize: Use fold_xx_to_i for rem
Posted by Luis Fernando Fujita Pires 4 years, 3 months ago
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>

Re: [PATCH v4 46/51] tcg/optimize: Use fold_xx_to_i for rem
Posted by Richard Henderson 4 years, 3 months ago
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~