Skip to content

Commit 717d3f3

Browse files
committed
[VectorCombine] foldShuffleOfCastops - add initial shuffle(bitcast(x),bitcast(y)) -> bitcast(shuffle(x,y)) support
Just handle cases where the bitcast src/dst element counts are the same (future patches will add shuffle mask scaling)
1 parent a403ad9 commit 717d3f3

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ bool VectorCombine::foldShuffleOfCastops(Instruction &I) {
14591459
return false;
14601460

14611461
Instruction::CastOps Opcode = C0->getOpcode();
1462-
if (Opcode == Instruction::BitCast || C0->getSrcTy() != C1->getSrcTy())
1462+
if (C0->getSrcTy() != C1->getSrcTy())
14631463
return false;
14641464

14651465
// Handle shuffle(zext_nneg(x), sext(y)) -> sext(shuffle(x,y)) folds.
@@ -1473,10 +1473,9 @@ bool VectorCombine::foldShuffleOfCastops(Instruction &I) {
14731473
auto *ShuffleDstTy = dyn_cast<FixedVectorType>(I.getType());
14741474
auto *CastDstTy = dyn_cast<FixedVectorType>(C0->getDestTy());
14751475
auto *CastSrcTy = dyn_cast<FixedVectorType>(C0->getSrcTy());
1476-
if (!ShuffleDstTy || !CastDstTy || !CastSrcTy)
1476+
if (!ShuffleDstTy || !CastDstTy || !CastSrcTy ||
1477+
CastDstTy->getElementCount() != CastSrcTy->getElementCount())
14771478
return false;
1478-
assert(CastDstTy->getElementCount() == CastSrcTy->getElementCount() &&
1479-
"Unexpected src/dst element counts");
14801479

14811480
auto *NewShuffleDstTy =
14821481
FixedVectorType::get(CastSrcTy->getScalarType(), Mask.size());

llvm/test/Transforms/VectorCombine/X86/shuffle-of-casts.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,12 @@ define <8 x double> @interleave_fpext_v4f32_v8f64(<4 x float> %a0, <4 x float> %
165165
ret <8 x double> %r
166166
}
167167

168-
; TODO - bitcasts (same element count)
168+
; bitcasts (same element count)
169169

170170
define <8 x float> @concat_bitcast_v4i32_v8f32(<4 x i32> %a0, <4 x i32> %a1) {
171171
; CHECK-LABEL: @concat_bitcast_v4i32_v8f32(
172-
; CHECK-NEXT: [[X0:%.*]] = bitcast <4 x i32> [[A0:%.*]] to <4 x float>
173-
; CHECK-NEXT: [[X1:%.*]] = bitcast <4 x i32> [[A1:%.*]] to <4 x float>
174-
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[X0]], <4 x float> [[X1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
172+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[A0:%.*]], <4 x i32> [[A1:%.*]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
173+
; CHECK-NEXT: [[R:%.*]] = bitcast <8 x i32> [[TMP1]] to <8 x float>
175174
; CHECK-NEXT: ret <8 x float> [[R]]
176175
;
177176
%x0 = bitcast <4 x i32> %a0 to <4 x float>

0 commit comments

Comments
 (0)