[llvm] [Reassociate] Resolve FIXME: No Lowering of FNeg to FMul unless it is safe (PR #85252)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 14 10:10:25 PDT 2024
================
@@ -287,11 +287,16 @@ static Instruction *CreateNeg(Value *S1, const Twine &Name,
static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
assert((isa<UnaryOperator>(Neg) || isa<BinaryOperator>(Neg)) &&
"Expected a Negate!");
- // FIXME: It's not safe to lower a unary FNeg into a FMul by -1.0.
unsigned OpNo = isa<BinaryOperator>(Neg) ? 1 : 0;
Type *Ty = Neg->getType();
- Constant *NegOne = Ty->isIntOrIntVectorTy() ?
- ConstantInt::getAllOnesValue(Ty) : ConstantFP::get(Ty, -1.0);
+ // Only lower to FMul if the operation is not a unary FNeg or Neg has the
+ // correct flags.
+ if (Ty->isFloatingPointTy() && isa<UnaryOperator>(Neg) &&
+ !hasFPAssociativeFlags(Neg))
----------------
dtcxzyw wrote:
```suggestion
if (Ty->isFPOrFPVectorTy() && isa<UnaryOperator>(Neg) &&
!Neg->hasNoNaNs())
```
Please add a scalar test and a vector test.
https://github.com/llvm/llvm-project/pull/85252
More information about the llvm-commits
mailing list