[llvm-commits] [llvm] r145681 - /llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
Craig Topper
craig.topper at gmail.com
Fri Dec 2 00:18:41 PST 2011
Author: ctopper
Date: Fri Dec 2 02:18:41 2011
New Revision: 145681
URL: http://llvm.org/viewvc/llvm-project?rev=145681&view=rev
Log:
Reduce duplicate code in isHorizontalBinOp and add some asserts to protect assumptions
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=145681&r1=145680&r2=145681&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Dec 2 02:18:41 2011
@@ -14329,9 +14329,18 @@
return false;
EVT VT = LHS.getValueType();
+
+ assert((VT.is128BitVector() || VT.is256BitVector()) &&
+ "Unsupported vector type for horizontal add/sub");
+
+ // Handle 128 and 256-bit vector lengths. AVX defines horizontal add/sub to
+ // operate independently on 128-bit lanes.
unsigned NumElts = VT.getVectorNumElements();
unsigned NumLanes = VT.getSizeInBits()/128;
unsigned NumLaneElts = NumElts / NumLanes;
+ assert((NumLaneElts % 2 == 0) &&
+ "Vector type should have an even number of elements in each lane");
+ unsigned HalfLaneElts = NumLaneElts/2;
// View LHS in the form
// LHS = VECTOR_SHUFFLE A, B, LMask
@@ -14394,40 +14403,23 @@
// LHS = VECTOR_SHUFFLE A, B, LMask
// RHS = VECTOR_SHUFFLE A, B, RMask
// Check that the masks correspond to performing a horizontal operation.
- for (unsigned l = 0; l != NumLanes; ++l) {
- unsigned LaneStart = l*NumLaneElts;
- for (unsigned i = 0; i != NumLaneElts/2; ++i) {
- unsigned LIdx = LMask[i+LaneStart];
- unsigned RIdx = RMask[i+LaneStart];
-
- // Ignore any UNDEF components.
- if (LIdx >= 2*NumElts || RIdx >= 2*NumElts ||
- (!A.getNode() && (LIdx < NumElts || RIdx < NumElts)) ||
- (!B.getNode() && (LIdx >= NumElts || RIdx >= NumElts)))
- continue;
-
- // Check that successive elements are being operated on. If not, this is
- // not a horizontal operation.
- if (!(LIdx == 2*i + LaneStart && RIdx == 2*i + LaneStart + 1) &&
- !(isCommutative && LIdx == 2*i + LaneStart + 1 && RIdx == 2*i + LaneStart))
- return false;
- }
- for (unsigned i = 0; i != NumLaneElts/2; ++i) {
- unsigned LIdx = LMask[i+(NumLaneElts/2)+LaneStart];
- unsigned RIdx = RMask[i+(NumLaneElts/2)+LaneStart];
-
- // Ignore any UNDEF components.
- if (LIdx >= 2*NumElts || RIdx >= 2*NumElts ||
- (!A.getNode() && (LIdx < NumElts || RIdx < NumElts)) ||
- (!B.getNode() && (LIdx >= NumElts || RIdx >= NumElts)))
- continue;
-
- // Check that successive elements are being operated on. If not, this is
- // not a horizontal operation.
- if (!(LIdx == 2*i + LaneStart + NumElts && RIdx == 2*i + LaneStart + NumElts + 1) &&
- !(isCommutative && LIdx == 2*i + LaneStart + NumElts + 1 && RIdx == 2*i + LaneStart + NumElts))
- return false;
- }
+ for (unsigned i = 0; i != NumElts; ++i) {
+ unsigned LIdx = LMask[i], RIdx = RMask[i];
+
+ // Ignore any UNDEF components.
+ if (LIdx >= 2*NumElts || RIdx >= 2*NumElts ||
+ (!A.getNode() && (LIdx < NumElts || RIdx < NumElts)) ||
+ (!B.getNode() && (LIdx >= NumElts || RIdx >= NumElts)))
+ continue;
+
+ // Check that successive elements are being operated on. If not, this is
+ // not a horizontal operation.
+ unsigned Src = (i/HalfLaneElts) % 2; // each lane is split between srcs
+ unsigned LaneStart = (i/NumLaneElts) * NumLaneElts;
+ unsigned Index = 2*(i%HalfLaneElts) + NumElts*Src + LaneStart;
+ if (!(LIdx == Index && RIdx == Index + 1) &&
+ !(isCommutative && LIdx == Index + 1 && RIdx == Index))
+ return false;
}
LHS = A.getNode() ? A : B; // If A is 'UNDEF', use B for it.
More information about the llvm-commits
mailing list