<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dear all,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    Thanks a lot for your analysis and suggestion.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    Currently, I walk around in a way similar to what Hongbin said, by treating SCEV of URem specially to get the range.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    I guess maybe the rule of inference can be updated haha ^_^</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    Thanks again for your time and answer!<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<span id="ms-rterangepaste-start"></span>
<div><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Best regards,</span></font><span style="font-size:12pt">
</span><span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">------------------------------------------</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Tingyuan LIANG</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">MPhil Student</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Department of Electronic and Computer Engineering</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">The Hong Kong University of Science and Technology</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span><span style="font-size:12pt"></span><span id="ms-rterangepaste-end"></span></div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Hongbin Zheng <etherzhhb@gmail.com><br>
<b>Sent:</b> Wednesday, June 26, 2019 1:57 PM<br>
<b>To:</b> Sanjoy Das<br>
<b>Cc:</b> Tingyuan LIANG; llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] Wrong Range of SCEV for URem</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">I feel that we maybe able to pattern match "%x -<nuw> ((%x udiv %y)<br>
*<nuw> %y)" to infer that the results should be smaller than %y. But<br>
not sure if this approach could scale well<br>
<br>
On Tue, Jun 25, 2019 at 8:50 PM Sanjoy Das via llvm-dev<br>
<llvm-dev@lists.llvm.org> wrote:<br>
><br>
> 1. There is nothing wrong about getUnsignedRange returning a range<br>
> with a negative value.  "Signed" and "Unsigned" are merely hints, the<br>
> underlying ConstantRange representation does not have a concept of<br>
> sign.  [A, B) represents all the values enumerated by "for (I = A; I<br>
> != B; I++ /*wrapping addition*/) { yield(I); }"<br>
><br>
> 2. I would guess this is because SCEV does not directly represent urem<br>
> but instead represents it as "%x urem %y == %x -<nuw> ((%x udiv %y)<br>
> *<nuw> %y)".  This makes it difficult for SCEV to infer that the X<br>
> urem 3 is u< 3.<br>
><br>
> On Wed, Jun 12, 2019 at 9:45 AM Tingyuan LIANG via llvm-dev<br>
> <llvm-dev@lists.llvm.org> wrote:<br>
> ><br>
> > Dear all,<br>
> ><br>
> >     Hi! I noticed an interesting situation when using getUnsignedRange and getSignedRange of SCEV for URem instruction.<br>
> >     Here is an example with 2 IR instructions:<br>
> ><br>
> >          %rem.lhs.trunc = trunc i32 %i15.082 to i8 -->  getUnsignedRange --> [1,50)<br>
> >          %rem81 = urem i8 %rem.lhs.trunc, 3  -->  getUnsignedRange --> [-47,50)<br>
> ><br>
> >     The problems are:<br>
> >         1) From my perspective, the getUnsignedRange() function should return non-negative range but it seems not so in the example. Is there anything wrong?<br>
> >         2) The range of the IR %rem81 should be [0,3), considering the equation: X%3 < 3?<br>
> ><br>
> >     Thanks in advance for your time and suggestions!<br>
> ><br>
> ><br>
> > Best regards,<br>
> > ------------------------------------------<br>
> > Tingyuan LIANG<br>
> > MPhil Student<br>
> > Department of Electronic and Computer Engineering<br>
> > The Hong Kong University of Science and Technology<br>
> > _______________________________________________<br>
> > LLVM Developers mailing list<br>
> > llvm-dev@lists.llvm.org<br>
> > <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> llvm-dev@lists.llvm.org<br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</div>
</span></font></div>
</body>
</html>