[llvm] 83e420c - [Constant] Inline ConstantInt::getSigned
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 22 09:32:01 PDT 2023
Author: Craig Topper
Date: 2023-03-22T09:31:51-07:00
New Revision: 83e420c65f4a6c0b693af82cfd81ae58fd033f97
URL: https://github.com/llvm/llvm-project/commit/83e420c65f4a6c0b693af82cfd81ae58fd033f97
DIFF: https://github.com/llvm/llvm-project/commit/83e420c65f4a6c0b693af82cfd81ae58fd033f97.diff
LOG: [Constant] Inline ConstantInt::getSigned
ConstantInt::getSigned calls ConstantInt::get with the IsSigned flag set to true.
That flag normally defaults to false.
For always signed constants the code base is not consistent about whether
it uses ConstantInt::getSigned or ConstantInt::get with IsSigned set to true.
And it's not clear how to decide which way to use.
By making getSigned inline, both ways should generate the same code in
the end.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D146598
Added:
Modified:
llvm/include/llvm/IR/Constants.h
llvm/lib/IR/Constants.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 9cc56ecf8e97..baa4bac8c8e1 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -111,8 +111,12 @@ class ConstantInt final : public ConstantData {
/// either getSExtValue() or getZExtValue() will yield a correctly sized and
/// signed value for the type Ty.
/// Get a ConstantInt for a specific signed value.
- static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
- static Constant *getSigned(Type *Ty, int64_t V);
+ static ConstantInt *getSigned(IntegerType *Ty, int64_t V) {
+ return get(Ty, V, true);
+ }
+ static Constant *getSigned(Type *Ty, int64_t V) {
+ return get(Ty, V, true);
+ }
/// Return a ConstantInt with the specified value and an implied Type. The
/// type is the integer type that corresponds to the bit width of the value.
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index ba68e6be05b5..a4b00d92ea89 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -899,14 +899,6 @@ ConstantInt *ConstantInt::get(IntegerType *Ty, uint64_t V, bool isSigned) {
return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned));
}
-ConstantInt *ConstantInt::getSigned(IntegerType *Ty, int64_t V) {
- return get(Ty, V, true);
-}
-
-Constant *ConstantInt::getSigned(Type *Ty, int64_t V) {
- return get(Ty, V, true);
-}
-
Constant *ConstantInt::get(Type *Ty, const APInt& V) {
ConstantInt *C = get(Ty->getContext(), V);
assert(C->getType() == Ty->getScalarType() &&
More information about the llvm-commits
mailing list