@@ -1097,10 +1097,11 @@ static Instruction *foldToUnsignedSaturatedAdd(BinaryOperator &I) {
1097
1097
return nullptr ;
1098
1098
}
1099
1099
1100
- static Instruction *
1101
- canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (
1102
- BinaryOperator &I, InstCombiner::BuilderTy &Builder ) {
1100
+ Instruction *
1101
+ InstCombiner:: canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (
1102
+ BinaryOperator &I) {
1103
1103
assert ((I.getOpcode () == Instruction::Add ||
1104
+ I.getOpcode () == Instruction::Or ||
1104
1105
I.getOpcode () == Instruction::Sub) &&
1105
1106
" Expecting add/sub instruction" );
1106
1107
@@ -1114,7 +1115,7 @@ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(
1114
1115
m_Value (Select))))
1115
1116
return nullptr ;
1116
1117
1117
- // `add` is commutative; but for `sub`, "select" *must* be on RHS.
1118
+ // `add`/`or` is commutative; but for `sub`, "select" *must* be on RHS.
1118
1119
if (I.getOpcode () == Instruction::Sub && I.getOperand (1 ) != Select)
1119
1120
return nullptr ;
1120
1121
@@ -1140,13 +1141,13 @@ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(
1140
1141
X->getType ()->getScalarSizeInBits ()))))
1141
1142
return nullptr ;
1142
1143
1143
- // Sign-extending value can be sign -extended itself if we `add` it,
1144
- // or zero -extended if we `sub`tract it .
1144
+ // Sign-extending value can be zero -extended if we `sub`tract it,
1145
+ // or sign -extended otherwise .
1145
1146
auto SkipExtInMagic = [&I](Value *&V) {
1146
- if (I.getOpcode () == Instruction::Add)
1147
- match (V, m_SExtOrSelf (m_Value (V)));
1148
- else
1147
+ if (I.getOpcode () == Instruction::Sub)
1149
1148
match (V, m_ZExtOrSelf (m_Value (V)));
1149
+ else
1150
+ match (V, m_SExtOrSelf (m_Value (V)));
1150
1151
};
1151
1152
1152
1153
// Now, finally validate the sign-extending magic.
@@ -1169,7 +1170,7 @@ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(
1169
1170
if (!ShouldSignext)
1170
1171
std::swap (SignExtendingValue, Zero);
1171
1172
1172
- // If we should not perform sign-extension then we must add/subtract zero.
1173
+ // If we should not perform sign-extension then we must add/or/ subtract zero.
1173
1174
if (!match (Zero, m_Zero ()))
1174
1175
return nullptr ;
1175
1176
// Otherwise, it should be some constant, left-shifted by the same NBits we
@@ -1181,10 +1182,10 @@ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(
1181
1182
m_Shl (m_Constant (SignExtendingValueBaseConstant),
1182
1183
m_ZExtOrSelf (m_Specific (NBits)))))
1183
1184
return nullptr ;
1184
- // If we `add `, then the constant should be all-ones , else it should be one .
1185
- if (I.getOpcode () == Instruction::Add
1186
- ? !match (SignExtendingValueBaseConstant, m_AllOnes ())
1187
- : !match (SignExtendingValueBaseConstant, m_One ()))
1185
+ // If we `sub `, then the constant should be one , else it should be all-ones .
1186
+ if (I.getOpcode () == Instruction::Sub
1187
+ ? !match (SignExtendingValueBaseConstant, m_One ())
1188
+ : !match (SignExtendingValueBaseConstant, m_AllOnes ()))
1188
1189
return nullptr ;
1189
1190
1190
1191
auto *NewAShr = BinaryOperator::CreateAShr (X, LowBitsToSkip,
@@ -1403,8 +1404,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
1403
1404
return V;
1404
1405
1405
1406
if (Instruction *V =
1406
- canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (
1407
- I, Builder))
1407
+ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (I))
1408
1408
return V;
1409
1409
1410
1410
if (Instruction *SatAdd = foldToUnsignedSaturatedAdd (I))
@@ -2006,8 +2006,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
2006
2006
}
2007
2007
2008
2008
if (Instruction *V =
2009
- canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (
2010
- I, Builder))
2009
+ canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract (I))
2011
2010
return V;
2012
2011
2013
2012
if (Instruction *Ext = narrowMathIfNoOverflow (I))
0 commit comments