llvm IRBuilder<>::CreateUDiv/CreateSDiv/CreateExactUDiv
I've seen that to create division operations there is variety of possibilities, UDiv/SDiv and ExactUDiv,
i infer that the difference between U and S stand for Unsigned and Signed, but that means that the sign is ignored for Unsigned?
also, what means Exact? that the result is a float?
Also, what do开发者_运维技巧es mean NSWAdd and NUWAdd? i could not find any documentation
I assume LLVM uses two's complement to store integers and in that case a (signed) negative number will seem like a large unsigned number for UDiv, (e.g. the two's complement representation for 32-bit -1
is 0xFFFFFFFF
). Thus SDiv(-16, 2) == -8
while UDiv(-16, 2) == 2147483640
.
So in short: no, the sign is not just ignored for unsigned. If you want that you need to solve it by taking the absolute value of the signed value for that.
What I can infer from here it seems the exact div instructions are when it is known that the division has no remainder. This makes it easier to optimize.
Further more as is stated here; NSW and NUW mean "No Signed Wrap" and "No Unsigned Wrap" which means that a trap value is generated if wrapping occurs (consider UAdd(-1, -1)
with the knowledge gained from above).
精彩评论