@@ -2265,14 +2265,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2265
2265
2266
2266
// max X, -X --> fabs X
2267
2267
// min X, -X --> -(fabs X)
2268
- // TODO: Remove one-use limitation? That is obviously better for max.
2269
- // It would be an extra instruction for min (fnabs), but that is
2270
- // still likely better for analysis and codegen.
2271
- if ((match (Arg0, m_OneUse (m_FNeg (m_Value (X)))) && Arg1 == X) ||
2272
- (match (Arg1, m_OneUse (m_FNeg (m_Value (X)))) && Arg0 == X)) {
2268
+ if ((match (Arg0, m_OneUse (m_FNeg (m_Value (X)))) &&
2269
+ match (Arg1, m_Specific (X))) ||
2270
+ (match (Arg1, m_OneUse (m_FNeg (m_Value (X)))) &&
2271
+ match (Arg0, m_Specific (X)))) {
2273
2272
Value *R = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, X, II);
2274
- if (IID == Intrinsic::minimum || IID == Intrinsic::minnum)
2273
+ if (IID == Intrinsic::minimum || IID == Intrinsic::minnum) {
2275
2274
R = Builder.CreateFNegFMF (R, II);
2275
+ }
2276
+
2277
+ return replaceInstUsesWith (*II, R);
2278
+ }
2279
+
2280
+ // No one-use. Only for max.
2281
+ // TODO: Remove one-use limitation? That is obviously better for max,
2282
+ // hence why we don't check for one-use for that. However,
2283
+ // it would be an extra instruction for min (fnabs), but
2284
+ // that is still likely better for analysis and codegen. If so, delete
2285
+ // one-use version
2286
+ if ((((match (Arg0, m_FNeg (m_Value (X)))) && match (Arg1, m_Specific (X))) ||
2287
+ (match (Arg1, m_FNeg (m_Value (X))) && match (Arg0, m_Specific (X)))) &&
2288
+ IID != Intrinsic::minimum && IID != Intrinsic::minnum) {
2289
+ Value *R = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, X, II);
2276
2290
return replaceInstUsesWith (*II, R);
2277
2291
}
2278
2292
0 commit comments