<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - IRCE wouldn't deal with range checks which predicate is uge."
   href="https://bugs.llvm.org/show_bug.cgi?id=49012">49012</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IRCE wouldn't deal with range checks which predicate is uge.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jie.he.cn@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>recently, I tried to use llvm to optimize my code generated by a managed VM.
this VM will instrument many range check code before memory access operations.
I found the optimization IRCE wouldn't work when the range check with the
predicate "uge". I wrote the following c/c++ code to simulate my code, where
len is the max buf length:

void testIRCE(unsigned int * buf, unsigned int len, unsigned int
iteration_count) {
    if (iteration_count > 0) {
        unsigned int i = 0;
        do {
            if (i >= len) { // range check
                printf("overflow\n");
                return;
            }

            buf[i] = i;

            i ++;

        } while (i < iteration_count);
    }
}

the above code wouldn't be optimised as expected into 2 loops (iteration range
splitting). I checked the llvm code, found in function
InductiveRangeCheck::parseRangeCheckICmp(), it wouldn't deal with uge cases,
I'm not sure if it is intentional.

but I tried to modify the llvm IR code by replacing the uge to ult, and
interchanging the operands of next branch instruction. the optimization IRCE
works as expected.

my test command is below:
first, get a clean llvm IR file.
./clang++ -O3 -Xclang -disable-llvm-passes  ~/testRCE.cpp  -emit-llvm -S -o
~/testRCE.TBBA.ll

second, optimize it with other loop optimization.
./opt -gvn -simplifycfg -loop-simplify -loop-predication -licm -dce -mem2reg
-dce -jump-threading -lcssa -simplifycfg -loop-simplify  -dce -stats
-debug-pass=Executions ~/testRCE.TBBA.ll -S -o ~/testRCE.mem2reg.ll

finally, take IRCE.
./opt -irce-skip-profitability-checks -irce -dce -S ~/testRCE.mem2reg.ll -o
~/testRCE.irce.ll</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>