Skip to content

Commit

Permalink
[Constant] Inline ConstantInt::getSigned
Browse files Browse the repository at this point in the history
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
  • Loading branch information
topperc committed Mar 22, 2023
1 parent 8eb464f commit 83e420c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 6 additions & 2 deletions llvm/include/llvm/IR/Constants.h
Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions llvm/lib/IR/Constants.cpp
Expand Up @@ -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() &&
Expand Down

0 comments on commit 83e420c

Please sign in to comment.