[llvm] [VectorCombine] Allow shuffling with bitcast for not multiple offset for loadsize (PR #119139)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 13 06:14:58 PST 2025
================
----------------
ParkHanbum wrote:
I will explain based on the following IR.
```
+define <2 x i64> @gep01_bitcast_load_i32_from_v4i32_insert_v2i64(ptr align 1 dereferenceable(16) %p) {
; CHECK-LABEL: @gep01_bitcast_load_i32_from_v4i32_insert_v2i64(
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds <4 x i32>, ptr [[P:%.*]], i64 0, i64 1
-; CHECK-NEXT: [[S:%.*]] = load i64, ptr [[GEP]], align 1
-; CHECK-NEXT: [[R:%.*]] = insertelement <2 x i64> poison, i64 [[S]], i64 0
+; CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[P:%.*]], align 1
+; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 1, i32 2, i32 poison, i32 poison>
+; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[TMP2]] to <2 x i64>
; CHECK-NEXT: ret <2 x i64> [[R]]
;
```
We first create a vector identical to the one processed up to the `insertElement` in the original code by performing a self shuffle.
After that, `bitcast` is used to match the type returned by the original code.
Therefore, when `bitcast` is required, it is used to replace `insertelement` via self shuffle, and in this case, the source and destination types are the same minvecty.
https://github.com/llvm/llvm-project/pull/119139
More information about the llvm-commits
mailing list