[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 4 11:58:22 PDT 2025


================
@@ -0,0 +1,18 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int<s, 32>
+
+module {
+  cir.func @fold_shuffle_dynamic_vector_op_test() {
+    %alloca = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["r", init]
+    %vec = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+    %indices = cir.const #cir.const_vector<[#cir.int<8> : !s32i, #cir.int<7> : !s32i, #cir.int<6> : !s32i, #cir.int<5> : !s32i]> : !cir.vector<4 x !s32i>
+    %new_vec = cir.vec.shuffle.dynamic %vec : !cir.vector<4 x !s32i>, %indices : !cir.vector<4 x !s32i>
+    cir.store align(16) %new_vec, %alloca : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
+    cir.return
+  }
+
+  // CHECK: %[[NEW_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<4> : !s32i, #cir.int<3> : !s32i, #cir.int<2> : !s32i]> : !cir.vector<4 x !s32i>
----------------
andykaylor wrote:

It's not obvious to me from this check what the full form of the transformed function will be. I assume we're getting rid of some dead instructions here, but that's not clear from the check. I'd suggest showing the full transformed function with CHECK-NEXT to verify that no unnecessary artifacts were left behind.

It isn't obvious at all why "8, 7, 6, 5" yielded the result here. I see that those values are ANDed with 3 to use "0, 3, 2, 1" as the shuffle indexes. Maybe add another test with indexes that don't require the mask and add a comment explaining the masking here.

https://github.com/llvm/llvm-project/pull/142315


More information about the cfe-commits mailing list