Skip to content

Commit

Permalink
[AIE2] Replace 8x4->4x8 tranpose shuffle vector with vshuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentijnvdBeek committed Jun 15, 2024
1 parent 3338773 commit be3751a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
15 changes: 15 additions & 0 deletions llvm/lib/Target/AIE/AIE2PreLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ bool AIE2PreLegalizerCombinerImpl::tryCombineShuffleVector(
MI.eraseFromParent();
return true;
}

CombinerHelper::GeneratorType FourPartitionByTwo =
sectionGenerator(0, DstNumElts, 4, 2);
if (Helper.matchCombineShuffleVector(MI, FourPartitionByTwo, DstNumElts)) {
const Register Src1 = MI.getOperand(1).getReg();
const Register Src2 = MI.getOperand(2).getReg();
const Register ShuffleModeReg =
MRI.createGenericVirtualRegister(LLT::scalar(32));

MIB.buildConstant(ShuffleModeReg, 29);
MIB.buildInstr(AIE2::G_AIE_VSHUFFLE, {DstReg},
{Src1, Src2, ShuffleModeReg});
MI.eraseFromParent();
return true;
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,12 @@ body: |
...

---
name: shuffle_vector_32
name: shuffle_vector_32_4x4
legalized: false
body: |
bb.1.entry:
liveins: $x0, $x1
; CHECK-LABEL: name: shuffle_vector_32
; CHECK-LABEL: name: shuffle_vector_32_4x4
; CHECK: liveins: $x0, $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<16 x s32>) = COPY $x0
Expand All @@ -667,12 +667,12 @@ body: |
...

---
name: shuffle_vector_16
name: shuffle_vector_16_4x4
legalized: false
body: |
bb.1.entry:
liveins: $x0, $x1
; CHECK-LABEL: name: shuffle_vector_16
; CHECK-LABEL: name: shuffle_vector_16_4x4
; CHECK: liveins: $x0, $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<32 x s16>) = COPY $x0
Expand All @@ -689,12 +689,12 @@ body: |
...

---
name: shuffle_vector_8
name: shuffle_vector_8_4x4
legalized: false
body: |
bb.1.entry:
liveins: $x0, $x1
; CHECK-LABEL: name: shuffle_vector_8
; CHECK-LABEL: name: shuffle_vector_8_4x4
; CHECK: liveins: $x0, $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<64 x s8>) = COPY $x0
Expand All @@ -708,3 +708,69 @@ body: |
%0:_(<64 x s8>) = G_SHUFFLE_VECTOR %1:_(<64 x s8>), %2:_, shufflemask(0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, 51, 4, 20, 36, 52, 5, 21, 37, 53, 6, 22, 38, 54, 7, 23, 39, 55, 8, 24, 40, 56, 9, 25, 41, 57, 10, 26, 42, 58, 11, 27, 43, 59, 12, 28, 44, 60, 13, 29, 45, 61, 14, 30, 46, 62, 15, 31, 47, 63)
$x2 = COPY %0:_(<64 x s8>)
PseudoRET implicit $lr, implicit $x2
...

---
name: shuffle_vector_32_4x8
legalized: false
body: |
bb.1.entry:
liveins: $x0, $x1
; CHECK-LABEL: name: shuffle_vector_32_4x8
; CHECK: liveins: $x0, $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<16 x s32>) = COPY $x0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<16 x s32>) = COPY $x1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 29
; CHECK-NEXT: [[AIE_VSHUFFLE:%[0-9]+]]:_(<16 x s32>) = G_AIE_VSHUFFLE [[COPY]], [[COPY1]], [[C]](s32)
; CHECK-NEXT: $x2 = COPY [[AIE_VSHUFFLE]](<16 x s32>)
; CHECK-NEXT: PseudoRET implicit $lr, implicit $x2
%1:_(<16 x s32>) = COPY $x0
%2:_(<16 x s32>) = COPY $x1
%0:_(<16 x s32>) = G_SHUFFLE_VECTOR %1:_(<16 x s32>), %2:_, shufflemask(0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15 )
$x2 = COPY %0:_(<16 x s32>)
PseudoRET implicit $lr, implicit $x2
...

---
name: shuffle_vector_16_4x8
legalized: false
body: |
bb.1.entry:
liveins: $x0, $x1
; CHECK-LABEL: name: shuffle_vector_16_4x8
; CHECK: liveins: $x0, $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<32 x s16>) = COPY $x0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<32 x s16>) = COPY $x1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 29
; CHECK-NEXT: [[AIE_VSHUFFLE:%[0-9]+]]:_(<32 x s16>) = G_AIE_VSHUFFLE [[COPY]], [[COPY1]], [[C]](s32)
; CHECK-NEXT: $x2 = COPY [[AIE_VSHUFFLE]](<32 x s16>)
; CHECK-NEXT: PseudoRET implicit $lr, implicit $x2
%1:_(<32 x s16>) = COPY $x0
%2:_(<32 x s16>) = COPY $x1
%0:_(<32 x s16>) = G_SHUFFLE_VECTOR %1:_(<32 x s16>), %2:_, shufflemask(0, 1, 8, 9, 16, 17, 24, 25, 2, 3, 10, 11, 18, 19, 26, 27, 4, 5, 12, 13, 20, 21, 28, 29, 6, 7, 14, 15, 22, 23, 30, 31)
$x2 = COPY %0:_(<32 x s16>)
PseudoRET implicit $lr, implicit $x2
...

---
name: shuffle_vector_8_4x8
legalized: false
body: |
bb.1.entry:
liveins: $x0, $x1
; CHECK-LABEL: name: shuffle_vector_8_4x8
; CHECK: liveins: $x0, $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<64 x s8>) = COPY $x0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<64 x s8>) = COPY $x1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 29
; CHECK-NEXT: [[AIE_VSHUFFLE:%[0-9]+]]:_(<64 x s8>) = G_AIE_VSHUFFLE [[COPY]], [[COPY1]], [[C]](s32)
; CHECK-NEXT: $x2 = COPY [[AIE_VSHUFFLE]](<64 x s8>)
; CHECK-NEXT: PseudoRET implicit $lr, implicit $x2
%1:_(<64 x s8>) = COPY $x0
%2:_(<64 x s8>) = COPY $x1
%0:_(<64 x s8>) = G_SHUFFLE_VECTOR %1:_(<64 x s8>), %2:_, shufflemask(0, 1, 16, 17, 32, 33, 48, 49, 2, 3, 18, 19, 34, 35, 50, 51, 4, 5, 20, 21, 36, 37, 52, 53, 6, 7, 22, 23, 38, 39, 54, 55, 8, 9, 24, 25, 40, 41, 56, 57, 10, 11, 26, 27, 42, 43, 58, 59, 12, 13, 28, 29, 44, 45, 60, 61, 14, 15, 30, 31, 46, 47, 62, 63)
$x2 = COPY %0:_(<64 x s8>)
PseudoRET implicit $lr, implicit $x2

0 comments on commit be3751a

Please sign in to comment.