Dear all, Hi! I noticed an interesting situation when using getUnsignedRange and getSignedRange of SCEV for URem instruction. Here is an example with 2 IR instructions: %rem.lhs.trunc = trunc i32 %i15.082 to i8 --> getUnsignedRange --> [1,50) %rem81 = urem i8 %rem.lhs.trunc, 3 --> getUnsignedRange --> [-47,50) The problems are: 1) From my perspective, the getUnsignedRange() function should return non-negative range but it seems not so in the example. Is there anything wrong? 2) The range of the IR %rem81 should be [0,3), considering the equation: X%3 < 3? Thanks in advance for your time and suggestions! Best regards, ------------------------------------------ Tingyuan LIANG MPhil Student Department of Electronic and Computer Engineering The Hong Kong University of Science and Technology -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190612/1e25559f/attachment.html>
1. There is nothing wrong about getUnsignedRange returning a range with a negative value. "Signed" and "Unsigned" are merely hints, the underlying ConstantRange representation does not have a concept of sign. [A, B) represents all the values enumerated by "for (I = A; I != B; I++ /*wrapping addition*/) { yield(I); }" 2. I would guess this is because SCEV does not directly represent urem but instead represents it as "%x urem %y == %x -<nuw> ((%x udiv %y) *<nuw> %y)". This makes it difficult for SCEV to infer that the X urem 3 is u< 3. On Wed, Jun 12, 2019 at 9:45 AM Tingyuan LIANG via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Dear all, > > Hi! I noticed an interesting situation when using getUnsignedRange and getSignedRange of SCEV for URem instruction. > Here is an example with 2 IR instructions: > > %rem.lhs.trunc = trunc i32 %i15.082 to i8 --> getUnsignedRange --> [1,50) > %rem81 = urem i8 %rem.lhs.trunc, 3 --> getUnsignedRange --> [-47,50) > > The problems are: > 1) From my perspective, the getUnsignedRange() function should return non-negative range but it seems not so in the example. Is there anything wrong? > 2) The range of the IR %rem81 should be [0,3), considering the equation: X%3 < 3? > > Thanks in advance for your time and suggestions! > > > Best regards, > ------------------------------------------ > Tingyuan LIANG > MPhil Student > Department of Electronic and Computer Engineering > The Hong Kong University of Science and Technology > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
I feel that we maybe able to pattern match "%x -<nuw> ((%x udiv %y) *<nuw> %y)" to infer that the results should be smaller than %y. But not sure if this approach could scale well On Tue, Jun 25, 2019 at 8:50 PM Sanjoy Das via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > 1. There is nothing wrong about getUnsignedRange returning a range > with a negative value. "Signed" and "Unsigned" are merely hints, the > underlying ConstantRange representation does not have a concept of > sign. [A, B) represents all the values enumerated by "for (I = A; I > != B; I++ /*wrapping addition*/) { yield(I); }" > > 2. I would guess this is because SCEV does not directly represent urem > but instead represents it as "%x urem %y == %x -<nuw> ((%x udiv %y) > *<nuw> %y)". This makes it difficult for SCEV to infer that the X > urem 3 is u< 3. > > On Wed, Jun 12, 2019 at 9:45 AM Tingyuan LIANG via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > > > Dear all, > > > > Hi! I noticed an interesting situation when using getUnsignedRange and getSignedRange of SCEV for URem instruction. > > Here is an example with 2 IR instructions: > > > > %rem.lhs.trunc = trunc i32 %i15.082 to i8 --> getUnsignedRange --> [1,50) > > %rem81 = urem i8 %rem.lhs.trunc, 3 --> getUnsignedRange --> [-47,50) > > > > The problems are: > > 1) From my perspective, the getUnsignedRange() function should return non-negative range but it seems not so in the example. Is there anything wrong? > > 2) The range of the IR %rem81 should be [0,3), considering the equation: X%3 < 3? > > > > Thanks in advance for your time and suggestions! > > > > > > Best regards, > > ------------------------------------------ > > Tingyuan LIANG > > MPhil Student > > Department of Electronic and Computer Engineering > > The Hong Kong University of Science and Technology > > _______________________________________________ > > LLVM Developers mailing list > > llvm-dev at lists.llvm.org > > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev