<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - GVN Load widening eliminates PRE opportunities"
   href="https://llvm.org/bugs/show_bug.cgi?id=29110">29110</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVN Load widening eliminates PRE opportunities
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>danielcdh@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>davidxl@google.com, llvm-bugs@lists.llvm.org, wmi@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>void bar();

struct a{
  long long p;
  int x;
  int y;
};

int foo(struct a *t) {
  int ret = 0;
  for(;;) {
    switch(t->x) {
      case 1:
        bar();
        t->x = 2;
        break;
      case 2:
        ret += t->y;
        bar();
        t->x = 3;
        break;
      case 3:
        bar();
        break;
      case 4:
        return ret;
    }
  }
}

In function foo(), the load of t->x is partially redundant on case 1&2. In GVN,
the read of t->y in case 2 in combined to the load of t->x with a widen load.
As a result, PRE cannot happen on t->x, thus we have an extra load on case 1
and 2 for every iteration.

Load widening can eliminate one load in the expense of:
1. one trunc operation to the lower load
2. one shift operation to the higher load
3. potential to block PRE opportunity

Looks to me the benefit of this optimization does not justify its constraints.

Thoughts?</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>