@@ -454,6 +454,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
454454 {nxv2s64, p0, nxv2s64, 8 },
455455 })
456456 .clampScalar (0 , s8, s64)
457+ .minScalarOrElt (0 , s8)
457458 .lowerIf ([=](const LegalityQuery &Query) {
458459 return Query.Types [0 ].isScalar () &&
459460 Query.Types [0 ] != Query.MMODescrs [0 ].MemoryTy ;
@@ -861,6 +862,13 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
861862 .legalForCartesianProduct ({s32, v2s16, v4s8})
862863 .legalForCartesianProduct ({s64, v8s8, v4s16, v2s32})
863864 .legalForCartesianProduct ({s128, v16s8, v8s16, v4s32, v2s64, v2p0})
865+ .customIf ([=](const LegalityQuery &Query) {
866+ // Handle casts from i1 vectors to scalars.
867+ LLT DstTy = Query.Types [0 ];
868+ LLT SrcTy = Query.Types [1 ];
869+ return DstTy.isScalar () && SrcTy.isVector () &&
870+ SrcTy.getScalarSizeInBits () == 1 ;
871+ })
864872 .lowerIf ([=](const LegalityQuery &Query) {
865873 return Query.Types [0 ].isVector () != Query.Types [1 ].isVector ();
866874 })
@@ -1404,11 +1412,29 @@ bool AArch64LegalizerInfo::legalizeCustom(
14041412 return Helper.lowerAbsToCNeg (MI);
14051413 case TargetOpcode::G_ICMP:
14061414 return legalizeICMP (MI, MRI, MIRBuilder);
1415+ case TargetOpcode::G_BITCAST:
1416+ return legalizeBitcast (MI, Helper);
14071417 }
14081418
14091419 llvm_unreachable (" expected switch to return" );
14101420}
14111421
1422+ bool AArch64LegalizerInfo::legalizeBitcast (MachineInstr &MI,
1423+ LegalizerHelper &Helper) const {
1424+ assert (MI.getOpcode () == TargetOpcode::G_BITCAST && " Unexpected opcode" );
1425+ auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs ();
1426+ // We're trying to handle casts from i1 vectors to scalars but reloading from
1427+ // stack.
1428+ if (!DstTy.isScalar () || !SrcTy.isVector () ||
1429+ SrcTy.getElementType () != LLT::scalar (1 ))
1430+ return false ;
1431+
1432+ auto Load = Helper.createStackStoreLoad (SrcReg, DstTy);
1433+ Helper.MIRBuilder .buildCopy (DstReg, Load.getReg (0 ));
1434+ MI.eraseFromParent ();
1435+ return true ;
1436+ }
1437+
14121438bool AArch64LegalizerInfo::legalizeFunnelShift (MachineInstr &MI,
14131439 MachineRegisterInfo &MRI,
14141440 MachineIRBuilder &MIRBuilder,
0 commit comments