@@ -1928,18 +1928,24 @@ Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU,
1928
1928
if (!WideAddRec.first )
1929
1929
return nullptr ;
1930
1930
1931
- // Reuse the IV increment that SCEVExpander created. Recompute flags, unless
1932
- // the flags for both increments agree and it is safe to use the ones from
1933
- // the original inc. In that case, the new use of the wide increment won't
1934
- // be more poisonous.
1935
- bool NeedToRecomputeFlags =
1936
- !SCEVExpander::canReuseFlagsFromOriginalIVInc (OrigPhi, WidePhi,
1937
- DU.NarrowUse , WideInc) ||
1938
- DU.NarrowUse ->hasNoUnsignedWrap () != WideInc->hasNoUnsignedWrap () ||
1939
- DU.NarrowUse ->hasNoSignedWrap () != WideInc->hasNoSignedWrap ();
1931
+ auto CanUseWideInc = [&]() {
1932
+ if (!WideInc)
1933
+ return false ;
1934
+ // Reuse the IV increment that SCEVExpander created. Recompute flags,
1935
+ // unless the flags for both increments agree and it is safe to use the
1936
+ // ones from the original inc. In that case, the new use of the wide
1937
+ // increment won't be more poisonous.
1938
+ bool NeedToRecomputeFlags =
1939
+ !SCEVExpander::canReuseFlagsFromOriginalIVInc (
1940
+ OrigPhi, WidePhi, DU.NarrowUse , WideInc) ||
1941
+ DU.NarrowUse ->hasNoUnsignedWrap () != WideInc->hasNoUnsignedWrap () ||
1942
+ DU.NarrowUse ->hasNoSignedWrap () != WideInc->hasNoSignedWrap ();
1943
+ return WideAddRec.first == WideIncExpr &&
1944
+ Rewriter.hoistIVInc (WideInc, DU.NarrowUse , NeedToRecomputeFlags);
1945
+ };
1946
+
1940
1947
Instruction *WideUse = nullptr ;
1941
- if (WideAddRec.first == WideIncExpr &&
1942
- Rewriter.hoistIVInc (WideInc, DU.NarrowUse , NeedToRecomputeFlags))
1948
+ if (CanUseWideInc ())
1943
1949
WideUse = WideInc;
1944
1950
else {
1945
1951
WideUse = cloneIVUser (DU, WideAddRec.first );
0 commit comments