[llvm] InstCombine: fix transformation of bitwiseAnd to fabs (PR #71257)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 4 02:07:16 PDT 2023
================
@@ -2546,6 +2546,32 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
if (DestTy == Src->getType())
return replaceInstUsesWith(CI, Src);
+ // If we are clearing the sign bit of a floating-point value, convert this to
+ // fabs
+ //
+ // This is a generous interpretation for noimplicitfloat, this is not a true
+ // floating-point operation.
+ //
+ // Assumes any IEEE-represented type has the sign bit in the high bit.
+ if (!Builder.GetInsertBlock()->getParent()->hasFnAttribute(
+ Attribute::NoImplicitFloat) &&
+ DestTy->isFloatingPointTy() && DestTy->isIEEE()) {
+ Value *L, *R;
+ if (match(Src, m_And(m_Value(L), m_Value(R)))) {
+ Value *Cast;
+ if (match(L, m_BitCast(m_Value(Cast))) && match(R, m_MaxSignedValue())) {
----------------
dtcxzyw wrote:
```suggestion
Value *Cast;
if (match(Src, m_And(m_BitCast(m_Value(Cast)), m_MaxSignedValue()))) {
```
https://github.com/llvm/llvm-project/pull/71257
More information about the llvm-commits
mailing list