Lei Zhang via llvm-dev
2018-Nov-19 22:51 UTC
[llvm-dev] Issue with getting unsigned Constant from APInt
Hi there, I have been trying to obtain a Constant from an APInt using ``` auto maskConstant = llvm::ConstantInt::get(intTy, maskPiece); ``` where `intTy` is a IntergerType pointer (64-bit) and `maskPiece` is an APInt object. However, if `maskPiece` has the a big value say 18374686479671623680, which is 1111111100000000000000000000000000000000000000000000000000000000. The constant will return a negative value -72057594037927936, which looks it is always converted to a signed integer. How can i keep it as unsigned? I have also tried `maskConstant = llvm::ConstantInt::get(intTy, maskPiece.getZExtValue(), false);` or `maskConstant llvm::ConstantInt::get(intTy, maskPiece.getZExtValue(), false);`, both returned the same negative value. Any help will be appreciated. Best regards, Leo Z -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181119/78ee1f81/attachment.html>
Friedman, Eli via llvm-dev
2018-Nov-19 23:09 UTC
[llvm-dev] Issue with getting unsigned Constant from APInt
On 11/19/2018 2:51 PM, Lei Zhang via llvm-dev wrote:> > Hi there, > > I have been trying to obtain a Constant from an APInt using > ``` > auto maskConstant = llvm::ConstantInt::get(intTy, maskPiece); > ``` > where `intTy` is a IntergerType pointer (64-bit) and `maskPiece` is an > APInt object. However, if `maskPiece` has the a big value say > 18374686479671623680, which is > 1111111100000000000000000000000000000000000000000000000000000000. The > constant will return a negative value -72057594037927936, which looks > it is always converted to a signed integer. How can i keep it as unsigned? >"i64 18374686479671623680" and "i64 -72057594037927936" are actually the same value in LLVM IR. dump() prints the signed version, but that's just for convenience (since "i64 -1" is easier to read). Integer operations have separate signed and unsigned versions where it's relevant (e.g. sdiv vs. udiv). -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181119/e4c96f3d/attachment.html>