[llvm] r231443 - LegalizeTypes: Handle shift by 0 in ExpandShiftByConstant.
Michael Zolotukhin
mzolotukhin at apple.com
Thu Mar 5 17:13:02 PST 2015
Author: mzolotukhin
Date: Thu Mar 5 19:13:01 2015
New Revision: 231443
URL: http://llvm.org/viewvc/llvm-project?rev=231443&view=rev
Log:
LegalizeTypes: Handle shift by 0 in ExpandShiftByConstant.
Though such shifts are usually optimized away by combiner, we still can
encounter them after a vector shift is legalized.
Added:
llvm/trunk/test/CodeGen/X86/vec_shift7.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp?rev=231443&r1=231442&r2=231443&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp Thu Mar 5 19:13:01 2015
@@ -1333,12 +1333,19 @@ std::pair <SDValue, SDValue> DAGTypeLega
/// and the shift amount is a constant 'Amt'. Expand the operation.
void DAGTypeLegalizer::ExpandShiftByConstant(SDNode *N, unsigned Amt,
SDValue &Lo, SDValue &Hi) {
- assert(Amt && "Expected zero shifts to be already optimized away.");
SDLoc DL(N);
// Expand the incoming operand to be shifted, so that we have its parts
SDValue InL, InH;
GetExpandedInteger(N->getOperand(0), InL, InH);
+ // Though Amt shouldn't usually be 0, it's possible. E.g. when legalization
+ // splitted a vector shift, like this: <op1, op2> SHL <0, 2>.
+ if (!Amt) {
+ Lo = InL;
+ Hi = InH;
+ return;
+ }
+
EVT NVT = InL.getValueType();
unsigned VTBits = N->getValueType(0).getSizeInBits();
unsigned NVTBits = NVT.getSizeInBits();
Added: llvm/trunk/test/CodeGen/X86/vec_shift7.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_shift7.ll?rev=231443&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/vec_shift7.ll (added)
+++ llvm/trunk/test/CodeGen/X86/vec_shift7.ll Thu Mar 5 19:13:01 2015
@@ -0,0 +1,12 @@
+; RUN: llc < %s -march=x86 -mcpu=yonah | FileCheck %s
+
+
+; Verify that we don't fail when shift by zero is encountered.
+
+define i64 @test1(<2 x i64> %a) {
+entry:
+ %c = shl <2 x i64> %a, <i64 0, i64 2>
+ %d = extractelement <2 x i64> %c, i32 0
+ ret i64 %d
+}
+; CHECK-LABEL: test1
More information about the llvm-commits
mailing list