Index: llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -5248,6 +5248,10 @@ LLT ShTy = MRI.getType(Z); unsigned BW = Ty.getScalarSizeInBits(); + + if (!isPowerOf2_32(BW)) + return UnableToLegalize; + const bool IsFSHL = MI.getOpcode() == TargetOpcode::G_FSHL; unsigned RevOpcode = IsFSHL ? TargetOpcode::G_FSHR : TargetOpcode::G_FSHL; @@ -5346,8 +5350,13 @@ bool IsFSHL = MI.getOpcode() == TargetOpcode::G_FSHL; unsigned RevOpcode = IsFSHL ? TargetOpcode::G_FSHR : TargetOpcode::G_FSHL; - if (LI.getAction({RevOpcode, {Ty, ShTy}}).Action == Lower) - return lowerFunnelShiftAsShifts(MI); + if (LI.getAction({RevOpcode, {Ty, ShTy}}).Action == Lower) { + // This only works for powers of 2, fallback to shifts if it fails. + LegalizerHelper::LegalizeResult Result = lowerFunnelShiftAsShifts(MI); + if (Result != UnableToLegalize) + return Result; + } + return lowerFunnelShiftWithInverse(MI); }