[llvm] r284874 - [DAG] enhance computeKnownBits to handle SHL with vector splat constant
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 13:16:27 PDT 2016
Author: spatel
Date: Fri Oct 21 15:16:27 2016
New Revision: 284874
URL: http://llvm.org/viewvc/llvm-project?rev=284874&view=rev
Log:
[DAG] enhance computeKnownBits to handle SHL with vector splat constant
Also, use APInt to avoid crashing on types larger than vNi64.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/test/CodeGen/X86/combine-shl.ll
llvm/trunk/test/CodeGen/X86/negate.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=284874&r1=284873&r2=284874&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Oct 21 15:16:27 2016
@@ -2144,23 +2144,21 @@ void SelectionDAG::computeKnownBits(SDVa
KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1);
break;
case ISD::SHL:
- // (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0
- if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
- unsigned ShAmt = SA->getZExtValue();
-
+ if (ConstantSDNode *SA = isConstOrConstSplat(Op.getOperand(1))) {
// If the shift count is an invalid immediate, don't do anything.
- if (ShAmt >= BitWidth)
+ APInt ShAmt = SA->getAPIntValue();
+ if (ShAmt.uge(BitWidth))
break;
- computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1);
- KnownZero <<= ShAmt;
- KnownOne <<= ShAmt;
+ computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth + 1);
+ KnownZero = KnownZero << ShAmt;
+ KnownOne = KnownOne << ShAmt;
// low bits known zero.
- KnownZero |= APInt::getLowBitsSet(BitWidth, ShAmt);
+ KnownZero |= APInt::getLowBitsSet(BitWidth, ShAmt.getZExtValue());
}
break;
case ISD::SRL:
- // (ushr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0
+ // FIXME: Reuse isConstOrConstSplat + APInt from above.
if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
unsigned ShAmt = SA->getZExtValue();
@@ -2177,6 +2175,7 @@ void SelectionDAG::computeKnownBits(SDVa
}
break;
case ISD::SRA:
+ // FIXME: Reuse isConstOrConstSplat + APInt from above.
if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
unsigned ShAmt = SA->getZExtValue();
Modified: llvm/trunk/test/CodeGen/X86/combine-shl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/combine-shl.ll?rev=284874&r1=284873&r2=284874&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/combine-shl.ll (original)
+++ llvm/trunk/test/CodeGen/X86/combine-shl.ll Fri Oct 21 15:16:27 2016
@@ -61,16 +61,12 @@ define <4 x i32> @combine_vec_shl_by_zer
define <4 x i32> @combine_vec_shl_known_zero0(<4 x i32> %x) {
; SSE-LABEL: combine_vec_shl_known_zero0:
; SSE: # BB#0:
-; SSE-NEXT: pxor %xmm1, %xmm1
-; SSE-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2],xmm0[3],xmm1[4],xmm0[5],xmm1[6],xmm0[7]
-; SSE-NEXT: pslld $16, %xmm0
+; SSE-NEXT: xorps %xmm0, %xmm0
; SSE-NEXT: retq
;
; AVX-LABEL: combine_vec_shl_known_zero0:
; AVX: # BB#0:
-; AVX-NEXT: vpxor %xmm1, %xmm1, %xmm1
-; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2],xmm0[3],xmm1[4],xmm0[5],xmm1[6],xmm0[7]
-; AVX-NEXT: vpslld $16, %xmm0, %xmm0
+; AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
; AVX-NEXT: retq
%1 = and <4 x i32> %x, <i32 4294901760, i32 4294901760, i32 4294901760, i32 4294901760>
%2 = shl <4 x i32> %1, <i32 16, i32 16, i32 16, i32 16>
Modified: llvm/trunk/test/CodeGen/X86/negate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/negate.ll?rev=284874&r1=284873&r2=284874&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/negate.ll (original)
+++ llvm/trunk/test/CodeGen/X86/negate.ll Fri Oct 21 15:16:27 2016
@@ -35,10 +35,7 @@ define i8 @negate_zero_or_minsigned_nsw(
define <4 x i32> @negate_zero_or_minsigned_nsw_vec(<4 x i32> %x) {
; CHECK-LABEL: negate_zero_or_minsigned_nsw_vec:
; CHECK: # BB#0:
-; CHECK-NEXT: pslld $31, %xmm0
-; CHECK-NEXT: pxor %xmm1, %xmm1
-; CHECK-NEXT: psubd %xmm0, %xmm1
-; CHECK-NEXT: movdqa %xmm1, %xmm0
+; CHECK-NEXT: xorps %xmm0, %xmm0
; CHECK-NEXT: retq
;
%signbit = shl <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
More information about the llvm-commits
mailing list