Commit 44ace7da91 for qemu.org

commit 44ace7da913a0fd49ec47b838f5c4b2ea304fa47
Author: Anton Johansson <anjo@rev.ng>
Date:   Fri Nov 13 00:20:29 2026 +0100

    target/hexagon: HLX, preserve scalar :mem_noshuf ordering

    A packet containing HLX instructions currently defers all stores to the
    end of the packet, this breaks scalar :mem_noshuf ordering.  Only
    reorder HLX stores.

    Fixes: a6fae6da070d66b9 ("target/hexagon: translate packets with HLX instructions")
    Signed-off-by: Anton Johansson <anjo@rev.ng>
    Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com>
    Reviewed-by: Marco Liebel <marco.liebel@oss.qualcomm.com>
    Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
index ec1d79e31f..11b3917b96 100644
--- a/target/hexagon/translate.c
+++ b/target/hexagon/translate.c
@@ -1533,8 +1533,10 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
             for (int pass = 0; pass < 3; pass++) {
                 for (i = 0; i < ctx->pkt.num_insns; i++) {
                     Insn *insn = &ctx->pkt.insn[i];
+                    bool hlx = GET_ATTRIB(insn->opcode, A_HLX);
                     bool tmp = GET_ATTRIB(insn->opcode, A_HLX_TMP);
-                    bool store = !tmp && GET_ATTRIB(insn->opcode, A_STORE);
+                    bool store = !tmp && hlx &&
+                                 GET_ATTRIB(insn->opcode, A_STORE);
                     if (pass != (tmp ? 0 : store ? 2 : 1)) {
                         continue;
                     }
@@ -1542,8 +1544,7 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
                     if (insn->hlx_new_zero) {
                         gen_hlx_new_zero(insn);
                     }
-                    if (GET_ATTRIB(insn->opcode, A_HLX) &&
-                        trace_event_get_state_backends(
+                    if (hlx && trace_event_get_state_backends(
                             TRACE_HEXAGON_HLX_OP)) {
                         gen_helper_hlx_trace_op(tcg_env,
                             tcg_constant_i32(insn->opcode));
diff --git a/tests/tcg/hexagon/hlx_mem.c b/tests/tcg/hexagon/hlx_mem.c
index 643b499fd9..c0844646a0 100644
--- a/tests/tcg/hexagon/hlx_mem.c
+++ b/tests/tcg/hexagon/hlx_mem.c
@@ -229,6 +229,25 @@ static void test_store_fault(void)
     check_h("LX_S16b_new (fault)", buf_out, expected, HLX_HALF_ELEMS);
 }

+static void test_preserve_scalar_noshuf(void)
+{
+    uint32_t ret = 0;
+    uint32_t ptr = 0;
+    uint32_t val = 0x1234;
+    asm volatile("{\n"
+                 ".word 0xe5007822\n"
+                 "    memw(%[ptr]) = %[val]\n"
+                 "    %[ret] = memw(%[ptr])\n"
+                 "}:mem_noshuf\n"
+                 : [ret] "=r"(ret)
+                 : [ptr] "r"(&ptr), [val] "r"(val)
+                 : "memory");
+    if (ret != val) {
+        printf("FAIL broken scalar :mem_noshuf ordering\n");
+        err++;
+    }
+}
+
 int main(void)
 {
     init_vtcm();
@@ -253,6 +272,9 @@ int main(void)
     /* Store in a faulting packet */
     test_store_fault();

+    /* Make sure HLX packets preserve scalar :mem_noshuf ordering */
+    test_preserve_scalar_noshuf();
+
     puts(err ? "FAIL" : "PASS");
     return err;
 }