@@ -1975,10 +1975,10 @@ static bool foldFCmpToFPClassTest(CmpInst *Cmp, const TargetLowering &TLI,
1975
1975
return true ;
1976
1976
}
1977
1977
1978
- static bool isRemOfLoopIncrementWithLoopInvariant (
1979
- Instruction *Rem, const LoopInfo *LI, Value *&RemAmtOut ,
1980
- std::optional< bool > &AddOrSubOut, Value *&AddOrSubInstOut ,
1981
- Value *&AddOrSubOffsetOut, PHINode *&LoopIncrPNOut) {
1978
+ static bool isRemOfLoopIncrementWithLoopInvariant (Instruction *Rem,
1979
+ const LoopInfo *LI,
1980
+ Value *&RemAmtOut ,
1981
+ PHINode *&LoopIncrPNOut) {
1982
1982
Value *Incr, *RemAmt;
1983
1983
// NB: If RemAmt is a power of 2 it *should* have been transformed by now.
1984
1984
if (!match (Rem, m_URem (m_Value (Incr), m_Value (RemAmt))))
@@ -1989,33 +1989,8 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
1989
1989
if (!L || !L->getLoopPreheader () || !L->getLoopLatch ())
1990
1990
return false ;
1991
1991
1992
- std::optional<bool > AddOrSub;
1993
- Value *AddOrSubOffset;
1994
1992
// Find out loop increment PHI.
1995
1993
auto *PN = dyn_cast<PHINode>(Incr);
1996
- if (PN) {
1997
- AddOrSub = std::nullopt;
1998
- AddOrSubOffset = nullptr ;
1999
- } else {
2000
- // Search through a NUW add/sub on top of the loop increment.
2001
- Value *V0, *V1;
2002
- if (match (Incr, m_NUWAddLike (m_Value (V0), m_Value (V1))))
2003
- AddOrSub = true ;
2004
- else if (match (Incr, m_NUWSub (m_Value (V0), m_Value (V1))))
2005
- AddOrSub = false ;
2006
- else
2007
- return false ;
2008
-
2009
- AddOrSubInstOut = Incr;
2010
-
2011
- PN = dyn_cast<PHINode>(V0);
2012
- if (PN != nullptr ) {
2013
- AddOrSubOffset = V1;
2014
- } else if (*AddOrSub) {
2015
- PN = dyn_cast<PHINode>(V1);
2016
- AddOrSubOffset = V0;
2017
- }
2018
- }
2019
1994
2020
1995
if (!PN)
2021
1996
return false ;
@@ -2052,8 +2027,6 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
2052
2027
// Set output variables.
2053
2028
RemAmtOut = RemAmt;
2054
2029
LoopIncrPNOut = PN;
2055
- AddOrSubOut = AddOrSub;
2056
- AddOrSubOffsetOut = AddOrSubOffset;
2057
2030
2058
2031
return true ;
2059
2032
}
@@ -2069,16 +2042,14 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
2069
2042
// for(i = Start; i < End; ++i, ++rem)
2070
2043
// Rem = rem == RemAmtLoopInvariant ? 0 : Rem;
2071
2044
//
2072
- // Currently only implemented for `Start` and ` IncrLoopInvariant` being zero.
2045
+ // Currently only implemented for `IncrLoopInvariant` being zero.
2073
2046
static bool foldURemOfLoopIncrement (Instruction *Rem, const DataLayout *DL,
2074
2047
const LoopInfo *LI,
2075
2048
SmallSet<BasicBlock *, 32 > &FreshBBs,
2076
2049
bool IsHuge) {
2077
- std::optional<bool > AddOrSub;
2078
- Value *AddOrSubOffset, *RemAmt, *AddOrSubInst;
2050
+ Value *RemAmt;
2079
2051
PHINode *LoopIncrPN;
2080
- if (!isRemOfLoopIncrementWithLoopInvariant (
2081
- Rem, LI, RemAmt, AddOrSub, AddOrSubInst, AddOrSubOffset, LoopIncrPN))
2052
+ if (!isRemOfLoopIncrementWithLoopInvariant (Rem, LI, RemAmt, LoopIncrPN))
2082
2053
return false ;
2083
2054
2084
2055
// Only non-constant remainder as the extra IV is probably not profitable
@@ -2102,26 +2073,6 @@ static bool foldURemOfLoopIncrement(Instruction *Rem, const DataLayout *DL,
2102
2073
// Only proceed if the expression simplifies (otherwise we can't fully
2103
2074
// optimize out the urem).
2104
2075
Value *Start = LoopIncrPN->getIncomingValueForBlock (L->getLoopPreheader ());
2105
- if (AddOrSub) {
2106
- assert (AddOrSubOffset && AddOrSubInst &&
2107
- " We found an add/sub but missing values" );
2108
- // Without dom-condition/assumption cache we aren't likely to get much out
2109
- // of a context instruction.
2110
- const SimplifyQuery Q (*DL);
2111
- bool NSW = cast<OverflowingBinaryOperator>(AddOrSubInst)->hasNoSignedWrap ();
2112
- if (*AddOrSub)
2113
- Start = simplifyAddInst (Start, AddOrSubOffset, /* IsNSW=*/ NSW,
2114
- /* IsNUW=*/ true , Q);
2115
- else
2116
- Start = simplifySubInst (Start, AddOrSubOffset, /* IsNSW=*/ NSW,
2117
- /* IsNUW=*/ true , Q);
2118
- if (!Start)
2119
- return false ;
2120
-
2121
- Start = simplifyURemInst (Start, RemAmt, Q);
2122
- if (!Start)
2123
- return false ;
2124
- }
2125
2076
2126
2077
// Create new remainder with induction variable.
2127
2078
Type *Ty = Rem->getType ();
@@ -2148,8 +2099,6 @@ static bool foldURemOfLoopIncrement(Instruction *Rem, const DataLayout *DL,
2148
2099
2149
2100
replaceAllUsesWith (Rem, NewRem, FreshBBs, IsHuge);
2150
2101
Rem->eraseFromParent ();
2151
- if (AddOrSubInst && AddOrSubInst->use_empty ())
2152
- cast<Instruction>(AddOrSubInst)->eraseFromParent ();
2153
2102
return true ;
2154
2103
}
2155
2104
0 commit comments