Added support for ceil/floor divide in the standard dialect. It works with signed integers with pos/neg nominator and/or denominator. The formula used as as follows:
c floorDiv(n, m) { x = (m<0) ? 1 : -1 return (n*m<0) ? - ((-n+x) / m) -1 : n / m ceilDiv(n, m) { x = (m > 0) ? -1 : 1 return (n*m>0) ? ((n+x) / m) + 1 : - (-n / m)
and was extensively tested before implementation. Note that there are two selects, and the first ones test whether the denominator is postive/negative. This test would go away in affine ceil/floor since the denominator is known to be negative. Since we do not have (I believe) the ability to indicate a non-negative signed integer at this time, the lowering of ceil/floor for affine functions are left in place, as it uses the more efficient technique with only 1 select per operation.
This patch added the constant folding, the canonicalization for div by 1, and lowering to LLVM. There are literal tests for each of these phases, and I added a more exhaustive integration test that verifies the correct results of divide by + or - 10 for integers from -20 to +20.
Isn't the "leading bit as sign" a bit too much detail in this comment.
Doesn't it suffice to say that it treats the inputs as signed entities?