Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1526,21 +1526,6 @@ } } - // If the LHS is an AND of a zext, and we have an equality compare, we can - // shrink the and/compare to the smaller type, eliminating the cast. - if (ZExtInst *Cast = dyn_cast(And->getOperand(0))) { - IntegerType *Ty = cast(Cast->getSrcTy()); - // Make sure we don't compare the upper bits, SimplifyDemandedBits - // should fold the icmp to true/false in that case. - if (Cmp.isEquality() && C1->getActiveBits() <= Ty->getBitWidth()) { - Value *NewAnd = Builder->CreateAnd(Cast->getOperand(0), - ConstantExpr::getTrunc(C2, Ty)); - NewAnd->takeName(And); - return new ICmpInst(Cmp.getPredicate(), NewAnd, - ConstantExpr::getTrunc(RHS, Ty)); - } - } - if (Instruction *I = foldICmpAndShift(Cmp, And, C1)) return I; Index: llvm/trunk/test/Transforms/InstCombine/cast.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/cast.ll +++ llvm/trunk/test/Transforms/InstCombine/cast.ll @@ -371,6 +371,21 @@ ret <2 x i1> %D } +; Verify that the 'and' was narrowed, the zext was eliminated, and the compare was narrowed +; even for vectors. Earlier folds should ensure that the icmp(and(zext)) pattern never occurs. + +define <2 x i1> @test32vec(<2 x i8> %A) { +; CHECK-LABEL: @test32vec( +; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> %A, +; CHECK-NEXT: [[D:%.*]] = icmp eq <2 x i8> [[TMP1]], +; CHECK-NEXT: ret <2 x i1> [[D]] +; + %B = zext <2 x i8> %A to <2 x i16> + %C = and <2 x i16> %B, + %D = icmp eq <2 x i16> %C, + ret <2 x i1> %D +} + define i32 @test33(i32 %c1) { ; CHECK-LABEL: @test33( ; CHECK-NEXT: ret i32 %c1