We already have overloaded binary arithemetic operators so you can write
A+B etc. This patch lets you write -A instead of neg(A).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/unittests/ADT/APFloatTest.cpp | ||
---|---|---|
3001 | Don't we need to keep the neg tests as well as adding the unary tests? |
llvm/unittests/ADT/APFloatTest.cpp | ||
---|---|---|
3001 | Fair enough, done, though I planned to remove APFloat::neg in a follow-up. |
llvm/include/llvm/ADT/APFloat.h | ||
---|---|---|
1253 | Why not make this a member of APFloat, just like the other operator overloads? | |
llvm/lib/IR/ConstantFold.cpp | ||
989 ↗ | (On Diff #246916) | Why change it? Calling operator-() seems a bit more elusive, than the neg. |
llvm/include/llvm/ADT/APFloat.h | ||
---|---|---|
1253 | Sure, I could do, but I don't see a compelling reason to do that and I thought it was simpler to follow the example of existing neg. Others would advise me to make the other operator overloads non-members instead. For example https://en.cppreference.com/w/cpp/language/operators says "Binary operators are typically implemented as non-members [...]". | |
llvm/lib/IR/ConstantFold.cpp | ||
989 ↗ | (On Diff #246916) | I think that's a matter of taste. If I didn't prefer -CV to neg(CV) then I wouldn't have bothered to implement operator-! |
llvm/include/llvm/ADT/APFloat.h | ||
---|---|---|
1253 | You are correct, placing it after the neg does make sense, and the quoted advise makes much sense as well. | |
llvm/lib/IR/ConstantFold.cpp | ||
989 ↗ | (On Diff #246916) | I agree, but in this case I would rather not change it, and maybe just use it for future uses. |
llvm/include/llvm/ADT/APFloat.h | ||
---|---|---|
1253 | OK, done. | |
llvm/lib/IR/ConstantFold.cpp | ||
989 ↗ | (On Diff #246916) | I'd prefer to remove neg altogether; see D75511. I'm keeping that as a separate patch to avoid a "flag day" change. I'd prefer to simplify the code at line 1338 to use overloaded operators too. There is still a case for keeping add() etc as functions, because they take an additional rounding mode argument. There is no reason to keep neg() as it is very simple and takes no additional arguments. |
llvm/lib/IR/ConstantFold.cpp | ||
---|---|---|
989 ↗ | (On Diff #246916) | Done, though I still don't understand why it's preferable. |
LGTM.
llvm/lib/IR/ConstantFold.cpp | ||
---|---|---|
989 ↗ | (On Diff #246916) | I think this way we get a simpler and stricter change, which all purpose is to add the new functionality (without changing any of the old one yet). And another change for changing/removing the old functionality. |
Why not make this a member of APFloat, just like the other operator overloads?