Skip to contentSkip to conversation

tcg: Fix constant folding of INDEX_op_extract2_i32

PATCH In review Richard Henderson 3 participants 3 messages Jul 9, 2019 – Jul 10, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg: Fix constant folding of INDEX_op_extract2_i32

On a 64-bit host, discard any replications of the 32-bit sign bit when performing the shift and merge.

---
 tcg/optimize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tcg/optimize.c +2 -2
index d7c71a6085..d2424de4af 100644
@@ -1213,8 +1213,8 @@ void tcg_optimize(TCGContext *s)
                 if (opc == INDEX_op_extract2_i64) {
                     tmp = (v1 >> op->args[3]) | (v2 << (64 - op->args[3]));
                 } else {
-                    tmp = (v1 >> op->args[3]) | (v2 << (32 - op->args[3]));
-                    tmp = (int32_t)tmp;
+                    tmp = (int32_t)(((uint32_t)v1 >> op->args[3]) |
+                                    ((uint32_t)v2 << (32 - op->args[3])));
                 }
                 tcg_opt_gen_movi(s, op, op->args[0], tmp);
                 break;
Signature · 1 line
2.17.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Richard Henderson

On a 64-bit host, discard any replications of the 32-bit sign bit when performing the shift and merge.

Quoted 9 lines
---
 tcg/optimize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tcg/optimize.c +0 -0
index d7c71a6085..d2424de4af 100644

tcg/optimize.c void tcg_optimize(TCGContext *s) · line 1220

Quoted 10 lines
tcg/optimize.c +2 -2
@@ -1213,8 +1213,8 @@ void tcg_optimize(TCGContext *s)
                 if (opc == INDEX_op_extract2_i64) {
                     tmp = (v1 >> op->args[3]) | (v2 << (64 - op->args[3]));
                 } else {
-                    tmp = (v1 >> op->args[3]) | (v2 << (32 - op->args[3]));
-                    tmp = (int32_t)tmp;
+                    tmp = (int32_t)(((uint32_t)v1 >> op->args[3]) |
+                                    ((uint32_t)v2 << (32 - op->args[3])));
                 }
                 tcg_opt_gen_movi(s, op, op->args[0], tmp);
                 break;

--
Alex Bennée

Tested-by
#2 lore raw
Quoted 4 lines · Alex Bennée

Richard Henderson <[email protected]> writes:

Quoted 9 lines
Quoted 5 lines

On a 64-bit host, discard any replications of the 32-bit sign bit when performing the shift and merge.

Hi,

I ran GCC validations with your fix, it does fix the problems I reported with the arm-none-linux-gnueabi target.

Unfortunately, we are unlucky because there are still regressions compared to qemu-3.1 when using the arm-none-linux-gnueabihf target, as well as arm-eabi and aarch64-elf.
I hoped all had the same root cause..... I'll report the remaining ones in a new launchpad bug.

Thanks

Christophe

Quoted 23 lines
Quoted 9 lines
---
 tcg/optimize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tcg/optimize.c +0 -0
index d7c71a6085..d2424de4af 100644

tcg/optimize.c void tcg_optimize(TCGContext *s) · line 1220

Quoted 10 lines
tcg/optimize.c +2 -2
@@ -1213,8 +1213,8 @@ void tcg_optimize(TCGContext *s)
                 if (opc == INDEX_op_extract2_i64) {
                     tmp = (v1 >> op->args[3]) | (v2 << (64 - op->args[3]));
                 } else {
-                    tmp = (v1 >> op->args[3]) | (v2 << (32 - op->args[3]));
-                    tmp = (int32_t)tmp;
+                    tmp = (int32_t)(((uint32_t)v1 >> op->args[3]) |
+                                    ((uint32_t)v2 << (32 - op->args[3])));
                 }
                 tcg_opt_gen_movi(s, op, op->args[0], tmp);
                 break;

--
Alex Bennée