[llvm] 14b03b4 - GlobalISel: Check for powers of 2 for inverse funnel shift lowering
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 20 08:30:52 PDT 2021
Author: Matt Arsenault
Date: 2021-04-20T11:30:22-04:00
New Revision: 14b03b4aadee8e6adcbb8c674c8d8f770b1bc4d6
URL: https://github.com/llvm/llvm-project/commit/14b03b4aadee8e6adcbb8c674c8d8f770b1bc4d6
DIFF: https://github.com/llvm/llvm-project/commit/14b03b4aadee8e6adcbb8c674c8d8f770b1bc4d6.diff
LOG: GlobalISel: Check for powers of 2 for inverse funnel shift lowering
This doesn't make a practical difference since it would only be broken
if a target actually had a legal non-power-of-2 inverse shift.
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 99b6ea805d9c..0ab80de694a8 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -5392,6 +5392,10 @@ LegalizerHelper::lowerFunnelShiftWithInverse(MachineInstr &MI) {
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;
@@ -5490,9 +5494,16 @@ LegalizerHelper::lowerFunnelShift(MachineInstr &MI) {
bool IsFSHL = MI.getOpcode() == TargetOpcode::G_FSHL;
unsigned RevOpcode = IsFSHL ? TargetOpcode::G_FSHR : TargetOpcode::G_FSHL;
+
+ // TODO: Use smarter heuristic that accounts for vector legalization.
if (LI.getAction({RevOpcode, {Ty, ShTy}}).Action == Lower)
return lowerFunnelShiftAsShifts(MI);
- return lowerFunnelShiftWithInverse(MI);
+
+ // This only works for powers of 2, fallback to shifts if it fails.
+ LegalizerHelper::LegalizeResult Result = lowerFunnelShiftWithInverse(MI);
+ if (Result == UnableToLegalize)
+ return lowerFunnelShiftAsShifts(MI);
+ return Result;
}
LegalizerHelper::LegalizeResult
More information about the llvm-commits
mailing list