@@ -2277,14 +2277,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2277
2277
2278
2278
// max X, -X --> fabs X
2279
2279
// min X, -X --> -(fabs X)
2280
- // TODO: Remove one-use limitation? That is obviously better for max.
2281
- // It would be an extra instruction for min (fnabs), but that is
2282
- // still likely better for analysis and codegen.
2283
- if ((match (Arg0, m_OneUse (m_FNeg (m_Value (X)))) && Arg1 == X) ||
2284
- (match (Arg1, m_OneUse (m_FNeg (m_Value (X)))) && Arg0 == X)) {
2280
+
2281
+ // No one-use. Only for max.
2282
+ // TODO: Remove one-use limitation? That is obviously better for max,
2283
+ // hence why we don't check for one-use for that. However,
2284
+ // it would be an extra instruction for min (fnabs), but
2285
+ // that is still likely better for analysis and codegen.
2286
+ // If so, then allow this if-statement clause to handle min,
2287
+ // and delete the clause below this one.
2288
+ if ((((match (Arg0, m_FNeg (m_Value (X)))) && match (Arg1, m_Specific (X))) ||
2289
+ (match (Arg1, m_FNeg (m_Value (X))) && match (Arg0, m_Specific (X)))) &&
2290
+ IID != Intrinsic::minimum && IID != Intrinsic::minnum) {
2291
+ Value *R = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, X, II);
2292
+ return replaceInstUsesWith (*II, R);
2293
+ }
2294
+
2295
+ // One-use version for min.
2296
+ if ((match (Arg0, m_OneUse (m_FNeg (m_Value (X)))) &&
2297
+ match (Arg1, m_Specific (X))) ||
2298
+ (match (Arg1, m_OneUse (m_FNeg (m_Value (X)))) &&
2299
+ match (Arg0, m_Specific (X)))) {
2285
2300
Value *R = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, X, II);
2286
- if (IID == Intrinsic::minimum || IID == Intrinsic::minnum)
2287
- R = Builder.CreateFNegFMF (R, II);
2301
+ R = Builder.CreateFNegFMF (R, II);
2288
2302
return replaceInstUsesWith (*II, R);
2289
2303
}
2290
2304
0 commit comments