@@ -2597,11 +2597,19 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) {
2597
2597
auto *SmallTy = cast<FixedVectorType>(ZExted->getType ());
2598
2598
unsigned BW = SmallTy->getElementType ()->getPrimitiveSizeInBits ();
2599
2599
2600
- // Check that the expression overall uses at most the same number of bits as
2601
- // ZExted
2602
- KnownBits KB = computeKnownBits (&I, *DL);
2603
- if (KB.countMaxActiveBits () > BW)
2604
- return false ;
2600
+ if (I.getOpcode () == Instruction::LShr) {
2601
+ // Check that the shift amount is less than the number of bits in the
2602
+ // smaller type. Otherwise, the smaller lshr will return a poison value.
2603
+ KnownBits ShAmtKB = computeKnownBits (I.getOperand (1 ), *DL);
2604
+ if (ShAmtKB.getMaxValue ().uge (BW))
2605
+ return false ;
2606
+ } else {
2607
+ // Check that the expression overall uses at most the same number of bits as
2608
+ // ZExted
2609
+ KnownBits KB = computeKnownBits (&I, *DL);
2610
+ if (KB.countMaxActiveBits () > BW)
2611
+ return false ;
2612
+ }
2605
2613
2606
2614
// Calculate costs of leaving current IR as it is and moving ZExt operation
2607
2615
// later, along with adding truncates if needed
@@ -2628,7 +2636,7 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) {
2628
2636
return false ;
2629
2637
2630
2638
// Check if we can propagate ZExt through its other users
2631
- KB = computeKnownBits (UI, *DL);
2639
+ KnownBits KB = computeKnownBits (UI, *DL);
2632
2640
if (KB.countMaxActiveBits () > BW)
2633
2641
return false ;
2634
2642
0 commit comments