[llvm] [InstCombine] Canonicalize the fcmp range check idiom into `fabs + fcmp` (PR #76367)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 21:01:07 PST 2024
================
@@ -1457,6 +1457,37 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS,
}
}
+ // Canonicalize the range check idiom:
+ // and (fcmp olt/ole/ult/ule x, C), (fcmp ogt/oge/ugt/uge x, -C)
+ // --> fabs(x) olt/ole/ult/ule C
+ // or (fcmp ogt/oge/ugt/uge x, C), (fcmp olt/ole/ult/ule x, -C)
+ // --> fabs(x) ogt/oge/ugt/uge C
+ // TODO: Generalize to handle a negated variable operand?
+ const APFloat *LHSC, *RHSC;
+ if (LHS->hasOneUse() && RHS->hasOneUse() && LHS0 == RHS0 &&
----------------
arsenm wrote:
Check LHS0 == RHS0 first?
https://github.com/llvm/llvm-project/pull/76367
More information about the llvm-commits
mailing list