llvm.org GIT mirror llvm / e32157c
Add signExtend to ConstantRange, to complement zeroExtend and truncate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35733 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 13 years ago
2 changed file(s) with 23 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
156156 /// zero extended to BitWidth.
157157 ConstantRange zeroExtend(uint32_t BitWidth) const;
158158
159 /// signExtend - Return a new range in the specified integer type, which must
160 /// be strictly larger than the current type. The returned range will
161 /// correspond to the possible range of values if the source range had been
162 /// sign extended to BitWidth.
163 ConstantRange signExtend(uint32_t BitWidth) const;
164
159165 /// truncate - Return a new range in the specified integer type, which must be
160166 /// strictly smaller than the current type. The returned range will
161167 /// correspond to the possible range of values if the source range had been
345345 return ConstantRange(L, U);
346346 }
347347
348 /// signExtend - Return a new range in the specified integer type, which must
349 /// be strictly larger than the current type. The returned range will
350 /// correspond to the possible range of values as if the source range had been
351 /// sign extended.
352 ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
353 unsigned SrcTySize = getBitWidth();
354 assert(SrcTySize < DstTySize && "Not a value extension");
355 if (isFullSet()) {
356 return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
357 APInt::getLowBitsSet(DstTySize, SrcTySize-1));
358 }
359
360 APInt L = Lower; L.sext(DstTySize);
361 APInt U = Upper; U.sext(DstTySize);
362 return ConstantRange(L, U);
363 }
364
348365 /// truncate - Return a new range in the specified integer type, which must be
349366 /// strictly smaller than the current type. The returned range will
350367 /// correspond to the possible range of values as if the source range had been