@@ -1171,14 +1171,15 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal,
1171
1171
return nullptr ;
1172
1172
}
1173
1173
1174
- static Instruction *canonicalizeSPF (SelectInst &Sel, ICmpInst &Cmp ,
1175
- InstCombinerImpl &IC) {
1174
+ static Value *canonicalizeSPF (ICmpInst &Cmp, Value *TrueVal, Value *FalseVal ,
1175
+ InstCombinerImpl &IC) {
1176
1176
Value *LHS, *RHS;
1177
1177
// TODO: What to do with pointer min/max patterns?
1178
- if (!Sel. getType ()->isIntOrIntVectorTy ())
1178
+ if (!TrueVal-> getType ()->isIntOrIntVectorTy ())
1179
1179
return nullptr ;
1180
1180
1181
- SelectPatternFlavor SPF = matchSelectPattern (&Sel, LHS, RHS).Flavor ;
1181
+ SelectPatternFlavor SPF =
1182
+ matchDecomposedSelectPattern (&Cmp, TrueVal, FalseVal, LHS, RHS).Flavor ;
1182
1183
if (SPF == SelectPatternFlavor::SPF_ABS ||
1183
1184
SPF == SelectPatternFlavor::SPF_NABS) {
1184
1185
if (!Cmp.hasOneUse () && !RHS->hasOneUse ())
@@ -1188,13 +1189,13 @@ static Instruction *canonicalizeSPF(SelectInst &Sel, ICmpInst &Cmp,
1188
1189
bool IntMinIsPoison = SPF == SelectPatternFlavor::SPF_ABS &&
1189
1190
match (RHS, m_NSWNeg (m_Specific (LHS)));
1190
1191
Constant *IntMinIsPoisonC =
1191
- ConstantInt::get (Type::getInt1Ty (Sel .getContext ()), IntMinIsPoison);
1192
+ ConstantInt::get (Type::getInt1Ty (Cmp .getContext ()), IntMinIsPoison);
1192
1193
Instruction *Abs =
1193
1194
IC.Builder .CreateBinaryIntrinsic (Intrinsic::abs, LHS, IntMinIsPoisonC);
1194
1195
1195
1196
if (SPF == SelectPatternFlavor::SPF_NABS)
1196
- return BinaryOperator:: CreateNeg (Abs); // Always without NSW flag!
1197
- return IC. replaceInstUsesWith (Sel, Abs) ;
1197
+ return IC. Builder . CreateNeg (Abs); // Always without NSW flag!
1198
+ return Abs;
1198
1199
}
1199
1200
1200
1201
if (SelectPatternResult::isMinOrMax (SPF)) {
@@ -1215,8 +1216,7 @@ static Instruction *canonicalizeSPF(SelectInst &Sel, ICmpInst &Cmp,
1215
1216
default :
1216
1217
llvm_unreachable (" Unexpected SPF" );
1217
1218
}
1218
- return IC.replaceInstUsesWith (
1219
- Sel, IC.Builder .CreateBinaryIntrinsic (IntrinsicID, LHS, RHS));
1219
+ return IC.Builder .CreateBinaryIntrinsic (IntrinsicID, LHS, RHS);
1220
1220
}
1221
1221
1222
1222
return nullptr ;
@@ -1677,8 +1677,9 @@ Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,
1677
1677
if (Instruction *NewSel = foldSelectValueEquivalence (SI, *ICI))
1678
1678
return NewSel;
1679
1679
1680
- if (Instruction *NewSPF = canonicalizeSPF (SI, *ICI, *this ))
1681
- return NewSPF;
1680
+ if (Value *V =
1681
+ canonicalizeSPF (*ICI, SI.getTrueValue (), SI.getFalseValue (), *this ))
1682
+ return replaceInstUsesWith (SI, V);
1682
1683
1683
1684
if (Value *V = foldSelectInstWithICmpConst (SI, ICI, Builder))
1684
1685
return replaceInstUsesWith (SI, V);
0 commit comments