[clang] [clang][bytecode] interp__builtin_ia32_pshuf - modulo lane index to allow reuse of PSHUFD/LW/HW mask decode. NFC (PR #162006)

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 5 04:16:18 PDT 2025


https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/162006

Removes need to offset PSHUFHW land index to extract the shuffle mask element

>From 12c7cbc961dcb05dd069f9dce5762e76283d1e76 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Sun, 5 Oct 2025 12:13:32 +0100
Subject: [PATCH] [clang][bytecode] interp__builtin_ia32_pshuf - modulo lane
 index to allow reuse of PSHUFD/LW/HW mask decode. NFC

Removes need to offset PSHUFHW land index to extract the shuffle mask element
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 6053237b1a261..68ebfdf27ba43 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2796,7 +2796,7 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, CodePtr OpPC,
     unsigned LaneBase = (Idx / LaneElts) * LaneElts;
     unsigned LaneIdx = Idx % LaneElts;
     unsigned SrcIdx = Idx;
-    unsigned Sel = (Ctl >> (2 * LaneIdx)) & 0x3;
+    unsigned Sel = (Ctl >> (2 * (LaneIdx & 0x3))) & 0x3;
     if (ElemBits == 32) {
       SrcIdx = LaneBase + Sel;
     } else {
@@ -2805,8 +2805,6 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, CodePtr OpPC,
       if (!IsShufHW && !InHigh) {
         SrcIdx = LaneBase + Sel;
       } else if (IsShufHW && InHigh) {
-        unsigned Rel = LaneIdx - HalfSize;
-        Sel = (Ctl >> (2 * Rel)) & 0x3;
         SrcIdx = LaneBase + HalfSize + Sel;
       }
     }



More information about the cfe-commits mailing list