Skip to content

Commit

Permalink
Add support for bfloat in SetExtract PreLegalizerCombiner
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinay-anubola committed Nov 21, 2024
1 parent 7a8f59c commit 0b3a94c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 13 deletions.
40 changes: 27 additions & 13 deletions llvm/lib/Target/AIE/AIE2PreLegalizerCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ bool AIE2PreLegalizerCombinerImpl::tryToCombineVectorShiftsByZero(

bool AIE2PreLegalizerCombinerImpl::tryToCombineSetExtract(
MachineInstr &MI) const {
// Compares the index registers and their associated constant values from two
// given machine instructions.
auto IsEqualIdx = [&](const MachineInstr *SetMI, const MachineInstr *ExtOp) {
const Register SetOpIdxReg = SetMI->getOperand(3).getReg();
const Register ExtOpIdxReg = ExtOp->getOperand(3).getReg();
auto SetOpCst = getIConstantVRegValWithLookThrough(SetOpIdxReg, MRI);
auto ExtOpCst = getIConstantVRegValWithLookThrough(ExtOpIdxReg, MRI);
if (SetOpIdxReg != ExtOpIdxReg &&
(!SetOpCst || !ExtOpCst ||
SetOpCst->Value.getZExtValue() != ExtOpCst->Value.getZExtValue()))
return false;
return true;
};
const Register DstReg = MI.getOperand(0).getReg();
MachineInstr *ExtOp = getDefIgnoringCopies(MI.getOperand(2).getReg(), MRI);

Expand All @@ -162,18 +175,18 @@ bool AIE2PreLegalizerCombinerImpl::tryToCombineSetExtract(
break;
}
case Intrinsic::aie2_set_I512_I256: {
if (cast<GIntrinsic>(*ExtOp).getIntrinsicID() !=
Intrinsic::aie2_ext_I256_I512)
return false;
const Register SetOpIdxReg = MI.getOperand(3).getReg();
const Register ExtOpIdxReg = ExtOp->getOperand(3).getReg();
auto SetOpCst = getIConstantVRegValWithLookThrough(SetOpIdxReg, MRI);
auto ExtOpCst = getIConstantVRegValWithLookThrough(ExtOpIdxReg, MRI);
if (SetOpIdxReg != ExtOpIdxReg &&
(!SetOpCst || !ExtOpCst ||
SetOpCst->Value.getZExtValue() != ExtOpCst->Value.getZExtValue()))
return false;
break;
if (cast<GIntrinsic>(*ExtOp).getIntrinsicID() ==
Intrinsic::aie2_ext_I256_I512 &&
IsEqualIdx(&MI, ExtOp))
break;
return false;
}
case Intrinsic::aie2_set_bf512_bf256: {
if (cast<GIntrinsic>(*ExtOp).getIntrinsicID() ==
Intrinsic::aie2_ext_bf256_bf512 &&
IsEqualIdx(&MI, ExtOp))
break;
return false;
}
default:
return false;
Expand Down Expand Up @@ -298,7 +311,8 @@ bool AIE2PreLegalizerCombinerImpl::tryToCombineIntrinsic(
case Intrinsic::aie2_set_I512_I128: {
return tryToCombineSetExtract(MI);
}
case Intrinsic::aie2_set_I512_I256: {
case Intrinsic::aie2_set_I512_I256:
case Intrinsic::aie2_set_bf512_bf256: {
return Combine256To512SetExtract && tryToCombineSetExtract(MI);
}
case Intrinsic::aie2_vinsert8_I512:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,63 @@ body: |
%3:_(<16 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.set.I512.I256), %2(<8 x s32>), %10(s32)
PseudoRET implicit $lr, implicit %3
...

---
name: set-extract-bf256
legalized: false
body: |
bb.1.entry:
liveins: $x0
; CHECK-LABEL: name: set-extract-bf256
; CHECK: liveins: $x0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<16 x s32>) = COPY $x0
; CHECK-NEXT: PseudoRET implicit $lr, implicit [[COPY]](<16 x s32>)
%0:_(<16 x s32>) = COPY $x0
%1:_(s32) = G_CONSTANT i32 0
%2:_(<8 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.ext.bf256.bf512), %0(<16 x s32>), %1(s32)
%3:_(<16 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.set.bf512.bf256), %2(<8 x s32>), %1(s32)
PseudoRET implicit $lr, implicit %3
...

---
name: set-extract-bf256_different_reg_same_idx
legalized: false
body: |
bb.1.entry:
liveins: $x0
; CHECK-LABEL: name: set-extract-bf256_different_reg_same_idx
; CHECK: liveins: $x0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<16 x s32>) = COPY $x0
; CHECK-NEXT: PseudoRET implicit $lr, implicit [[COPY]](<16 x s32>)
%0:_(<16 x s32>) = COPY $x0
%1:_(s32) = G_CONSTANT i32 0
%10:_(s32) = G_CONSTANT i32 0
%2:_(<8 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.ext.bf256.bf512), %0(<16 x s32>), %1(s32)
%3:_(<16 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.set.bf512.bf256), %2(<8 x s32>), %10(s32)
PseudoRET implicit $lr, implicit %3
...

---
name: set-extract-bf256_different_idx
legalized: false
body: |
bb.1.entry:
liveins: $x0
; CHECK-LABEL: name: set-extract-bf256_different_idx
; CHECK: liveins: $x0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<16 x s32>) = COPY $x0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
; CHECK-NEXT: [[INT:%[0-9]+]]:_(<8 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.ext.bf256.bf512), [[COPY]](<16 x s32>), [[C]](s32)
; CHECK-NEXT: [[INT1:%[0-9]+]]:_(<16 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.set.bf512.bf256), [[INT]](<8 x s32>), [[C1]](s32)
; CHECK-NEXT: PseudoRET implicit $lr, implicit [[INT1]](<16 x s32>)
%0:_(<16 x s32>) = COPY $x0
%1:_(s32) = G_CONSTANT i32 0
%10:_(s32) = G_CONSTANT i32 1
%2:_(<8 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.ext.bf256.bf512), %0(<16 x s32>), %1(s32)
%3:_(<16 x s32>) = G_INTRINSIC intrinsic(@llvm.aie2.set.bf512.bf256), %2(<8 x s32>), %10(s32)
PseudoRET implicit $lr, implicit %3
...

0 comments on commit 0b3a94c

Please sign in to comment.