[llvm] [Transforms] Resolve FIXME: No Lowering of FNeg to FMul unless it is safe (PR #85252)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 01:16:20 PDT 2024
================
@@ -287,11 +287,15 @@ 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->isFPOrFPVectorTy() && isa<UnaryOperator>(Neg) && !Neg->hasNoNaNs())
----------------
arsenm wrote:
Better to directly check for fneg? isa<UnaryOperator> that's floating point type isn't really obvious
https://github.com/llvm/llvm-project/pull/85252
More information about the llvm-commits
mailing list