The definition of urem is referring to a non-exact udiv. (An "exact"
urem would not be a very interesting function, since it would always
return either 0 or some kind of undef/poison value.) Non-exact udiv
rounds the result down (towards 0) to the next integer. I see that
this is not explicitly mentioned in the langref, though it does say it
returns the "unsigned integer quotient of the two operands", and
wikipedia says that the quotient "is commonly referred to as the
integer part of a division (in the case of Euclidean division)":
https://en.wikipedia.org/wiki/Quotient
Personally I think this is still a bit obscure, and it would be better
to explicitly say that it rounds down.
Jay.
On Fri, 1 Oct 2021 at 02:36, Vadim Zaliva via llvm-dev
<llvm-dev at lists.llvm.org> wrote:>
> I have a question about the semantics of the "urem a b" IR
instruction when "a/b" is not representable.
>
> The language reference states that "This instruction returns the
unsigned integer remainder of a division.
> This instruction always performs an unsigned division to get the
remainder."
>
> It does not specify what it returns in if a/b is not representable. For
example "udiv" definition says:
> "If the exact keyword is present, the result value of the udiv is a
poison value
> if %op1 is not a multiple of %op2 (as such, "((a udiv exact b) mul b)
== a")."
>
> So it is internally calling "exact udiv", the poison value
returned by it will cause "udev" return value to be a poison.
> However, if it is not using "exact," I am not sure what the
result would be.
>
> Could somebody clarify the intended semantics or "urem" for me?
Thanks!
>
> Vadim
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev