Index: llvm/trunk/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/trunk/lib/Analysis/ValueTracking.cpp +++ llvm/trunk/lib/Analysis/ValueTracking.cpp @@ -1451,9 +1451,10 @@ KnownOne.getBitWidth() == BitWidth && "V, KnownOne and KnownZero should have same BitWidth"); - if (const ConstantInt *CI = dyn_cast(V)) { - // We know all of the bits for a constant! - KnownOne = CI->getValue(); + const APInt *C; + if (match(V, m_APInt(C))) { + // We know all of the bits for a scalar constant or a splat vector constant! + KnownOne = *C; KnownZero = ~KnownOne; return; } Index: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2859,13 +2859,14 @@ // In general, it is possible for computeKnownBits to determine all bits in // a value even when the operands are not all constants. - if (ExpensiveCombines && !I->use_empty() && I->getType()->isIntegerTy()) { - unsigned BitWidth = I->getType()->getScalarSizeInBits(); + Type *Ty = I->getType(); + if (ExpensiveCombines && !I->use_empty() && Ty->isIntOrIntVectorTy()) { + unsigned BitWidth = Ty->getScalarSizeInBits(); APInt KnownZero(BitWidth, 0); APInt KnownOne(BitWidth, 0); computeKnownBits(I, KnownZero, KnownOne, /*Depth*/0, I); if ((KnownZero | KnownOne).isAllOnesValue()) { - Constant *C = ConstantInt::get(I->getContext(), KnownOne); + Constant *C = ConstantInt::get(Ty, KnownOne); DEBUG(dbgs() << "IC: ConstFold (all bits known) to: " << *C << " from: " << *I << '\n'); Index: llvm/trunk/test/Transforms/InstCombine/and.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/and.ll +++ llvm/trunk/test/Transforms/InstCombine/and.ll @@ -414,3 +414,14 @@ ret i32 %tmp.4 } +; FIXME: This test should only need -instsimplify (ValueTracking / computeKnownBits), not -instcombine. + +define <2 x i32> @PR24942(<2 x i32> %x) { +; CHECK-LABEL: @PR24942( +; CHECK-NEXT: ret <2 x i32> zeroinitializer +; + %lshr = lshr <2 x i32> %x, + %and = and <2 x i32> %lshr, + ret <2 x i32> %and +} + Index: llvm/trunk/test/Transforms/InstCombine/trunc.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/trunc.ll +++ llvm/trunk/test/Transforms/InstCombine/trunc.ll @@ -437,9 +437,7 @@ define <8 x i16> @trunc_shl_v8i16_v8i32_16(<8 x i32> %a) { ; CHECK-LABEL: @trunc_shl_v8i16_v8i32_16( -; CHECK-NEXT: [[SHL:%.*]] = shl <8 x i32> %a, -; CHECK-NEXT: [[CONV:%.*]] = trunc <8 x i32> [[SHL]] to <8 x i16> -; CHECK-NEXT: ret <8 x i16> [[CONV]] +; CHECK-NEXT: ret <8 x i16> zeroinitializer ; %shl = shl <8 x i32> %a, %conv = trunc <8 x i32> %shl to <8 x i16> @@ -448,9 +446,7 @@ define <8 x i16> @trunc_shl_v8i16_v8i32_17(<8 x i32> %a) { ; CHECK-LABEL: @trunc_shl_v8i16_v8i32_17( -; CHECK-NEXT: [[SHL:%.*]] = shl <8 x i32> %a, -; CHECK-NEXT: [[CONV:%.*]] = trunc <8 x i32> [[SHL]] to <8 x i16> -; CHECK-NEXT: ret <8 x i16> [[CONV]] +; CHECK-NEXT: ret <8 x i16> zeroinitializer ; %shl = shl <8 x i32> %a, %conv = trunc <8 x i32> %shl to <8 x i16>