Skip to content

Commit a22d1b5

Browse files
authored
[ConstantInt] Add ImplicitTrunc parameter to getSigned() (NFC) (llvm#172875)
For consistency with `ConstantInt::get()`, add an ImplicitTrunc parameter to `ConstantInt::getSigned()` as well. It currently defaults to true and will be flipped to false in the future (by llvm#171456).
1 parent 8994d39 commit a22d1b5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

llvm/include/llvm/IR/Constants.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ class ConstantInt final : public ConstantData {
133133
/// either getSExtValue() or getZExtValue() will yield a correctly sized and
134134
/// signed value for the type Ty.
135135
/// Get a ConstantInt for a specific signed value.
136-
static ConstantInt *getSigned(IntegerType *Ty, int64_t V) {
137-
return get(Ty, V, true);
136+
/// \param ImplicitTrunc Whether to allow implicit truncation of the value.
137+
// TODO: Make ImplicitTrunc default to false.
138+
static ConstantInt *getSigned(IntegerType *Ty, int64_t V,
139+
bool ImplicitTrunc = true) {
140+
return get(Ty, V, /*IsSigned=*/true, ImplicitTrunc);
138141
}
139-
static Constant *getSigned(Type *Ty, int64_t V) {
140-
return get(Ty, V, true);
142+
static Constant *getSigned(Type *Ty, int64_t V, bool ImplicitTrunc = true) {
143+
return get(Ty, V, /*IsSigned=*/true, ImplicitTrunc);
141144
}
142145

143146
/// Return a ConstantInt with the specified value and an implied Type. The

llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,8 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
11051105
uint64_t ElementSize = GTI.getSequentialElementStride(*DL);
11061106
IntegerType *PtrIdxTy = cast<IntegerType>(DL->getIndexType(GEP->getType()));
11071107
// If the element size overflows the type, truncate.
1108-
ConstantInt *ElementSizeIdx = ConstantInt::get(
1109-
PtrIdxTy, ElementSize, /*IsSigned=*/true, /*ImplicitTrunc=*/true);
1108+
ConstantInt *ElementSizeIdx =
1109+
ConstantInt::getSigned(PtrIdxTy, ElementSize, /*ImplicitTrunc=*/true);
11101110
if (ArrayIdx->getType()->getIntegerBitWidth() <=
11111111
DL->getIndexSizeInBits(GEP->getAddressSpace())) {
11121112
// Skip factoring if ArrayIdx is wider than the index size, because

0 commit comments

Comments
 (0)