@@ -83,8 +83,8 @@ static bool foldGuardedFunnelShift(Instruction &I, const DominatorTree &DT) {
8383 // == (ShVal0 << ShAmt) | (ShVal1 >> (Width -ShAmt))
8484 if (match (V, m_OneUse (m_c_Or (
8585 m_Shl (m_Value (ShVal0), m_Value (ShAmt)),
86- m_LShr (m_Value (ShVal1), m_Sub ( m_SpecificInt (Width),
87- m_Deferred (ShAmt))))))) {
86+ m_LShr (m_Value (ShVal1),
87+ m_Sub ( m_SpecificInt (Width), m_Deferred (ShAmt))))))) {
8888 return Intrinsic::fshl;
8989 }
9090
@@ -617,7 +617,7 @@ struct LoadOps {
617617 LoadInst *RootInsert = nullptr ;
618618 bool FoundRoot = false ;
619619 uint64_t LoadSize = 0 ;
620- uint64_t Shift = 0 ;
620+ const APInt * Shift = nullptr ;
621621 Type *ZextType;
622622 AAMDNodes AATags;
623623};
@@ -627,15 +627,17 @@ struct LoadOps {
627627// (ZExt(L1) << shift1) | ZExt(L2) -> ZExt(L3)
628628static bool foldLoadsRecursive (Value *V, LoadOps &LOps, const DataLayout &DL,
629629 AliasAnalysis &AA) {
630- uint64_t ShAmt2;
630+ const APInt * ShAmt2 = nullptr ;
631631 Value *X;
632632 Instruction *L1, *L2;
633633
634634 // Go to the last node with loads.
635- if (match (V,
636- m_OneUse (m_c_Or (m_Value (X), m_OneUse (m_ShlOrSelf (
637- m_OneUse (m_ZExt (m_Instruction (L2))),
638- ShAmt2)))))) {
635+ if (match (V, m_OneUse (m_c_Or (
636+ m_Value (X),
637+ m_OneUse (m_Shl (m_OneUse (m_ZExt (m_OneUse (m_Instruction (L2)))),
638+ m_APInt (ShAmt2)))))) ||
639+ match (V, m_OneUse (m_Or (m_Value (X),
640+ m_OneUse (m_ZExt (m_OneUse (m_Instruction (L2)))))))) {
639641 if (!foldLoadsRecursive (X, LOps, DL, AA) && LOps.FoundRoot )
640642 // Avoid Partial chain merge.
641643 return false ;
@@ -644,11 +646,11 @@ static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL,
644646
645647 // Check if the pattern has loads
646648 LoadInst *LI1 = LOps.Root ;
647- uint64_t ShAmt1 = LOps.Shift ;
649+ const APInt * ShAmt1 = LOps.Shift ;
648650 if (LOps.FoundRoot == false &&
649651 (match (X, m_OneUse (m_ZExt (m_Instruction (L1)))) ||
650652 match (X, m_OneUse (m_Shl (m_OneUse (m_ZExt (m_OneUse (m_Instruction (L1)))),
651- m_ConstantInt (ShAmt1)))))) {
653+ m_APInt (ShAmt1)))))) {
652654 LI1 = dyn_cast<LoadInst>(L1);
653655 }
654656 LoadInst *LI2 = dyn_cast<LoadInst>(L2);
@@ -724,6 +726,13 @@ static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL,
724726 if (IsBigEndian)
725727 std::swap (ShAmt1, ShAmt2);
726728
729+ // Find Shifts values.
730+ uint64_t Shift1 = 0 , Shift2 = 0 ;
731+ if (ShAmt1)
732+ Shift1 = ShAmt1->getZExtValue ();
733+ if (ShAmt2)
734+ Shift2 = ShAmt2->getZExtValue ();
735+
727736 // First load is always LI1. This is where we put the new load.
728737 // Use the merged load size available from LI1 for forward loads.
729738 if (LOps.FoundRoot ) {
@@ -738,7 +747,7 @@ static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL,
738747 uint64_t ShiftDiff = IsBigEndian ? LoadSize2 : LoadSize1;
739748 uint64_t PrevSize =
740749 DL.getTypeStoreSize (IntegerType::get (LI1->getContext (), LoadSize1));
741- if ((ShAmt2 - ShAmt1 ) != ShiftDiff || (Offset2 - Offset1) != PrevSize)
750+ if ((Shift2 - Shift1 ) != ShiftDiff || (Offset2 - Offset1) != PrevSize)
742751 return false ;
743752
744753 // Update LOps
@@ -815,7 +824,7 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL,
815824 // Check if shift needed. We need to shift with the amount of load1
816825 // shift if not zero.
817826 if (LOps.Shift )
818- NewOp = Builder.CreateShl (NewOp, LOps.Shift );
827+ NewOp = Builder.CreateShl (NewOp, ConstantInt::get (I. getContext (), * LOps.Shift ) );
819828 I.replaceAllUsesWith (NewOp);
820829
821830 return true ;
@@ -851,9 +860,11 @@ static std::optional<PartStore> matchPartStore(Instruction &I,
851860 return std::nullopt ;
852861
853862 uint64_t ValWidth = StoredTy->getPrimitiveSizeInBits ();
854- uint64_t ValOffset;
863+ uint64_t ValOffset = 0 ;
855864 Value *Val;
856- if (!match (StoredVal, m_Trunc (m_LShrOrSelf (m_Value (Val), ValOffset))))
865+ if (!match (StoredVal, m_CombineOr (m_Trunc (m_LShr (m_Value (Val),
866+ m_ConstantInt (ValOffset))),
867+ m_Trunc (m_Value (Val)))))
857868 return std::nullopt ;
858869
859870 Value *Ptr = Store->getPointerOperand ();
0 commit comments