<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 - [CorrelatedValuePropagation / LazyValueInfo] wrong code generation"
   href="https://bugs.llvm.org/show_bug.cgi?id=45384">45384</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[CorrelatedValuePropagation / LazyValueInfo]  wrong code generation
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>10.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>release blocker
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>paulsson@linux.vnet.ibm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23301" name="attach_23301" title="reduced testcase">attachment 23301</a> <a href="attachment.cgi?id=23301&action=edit" title="reduced testcase">[details]</a></span>
reduced testcase

Originates from
<a href="https://bugs.launchpad.net/ubuntu/+source/postgresql-12/+bug/1867173">https://bugs.launchpad.net/ubuntu/+source/postgresql-12/+bug/1867173</a>, where
Ubuntu is building (bootstrapped) clang-10 and runs into a seg fault with
llvm-lto.

I believe I have found a bug in clang-10 which seems to likely be involved in
this problem. This is a reduced test case, which involves an i8 PHI with an
undef entry operand, which is and:ed with 127, clearing the sign bit:

define i32 @fun() {
entry:
  br label %bb1

bb1:
  %P = phi i8 [ undef, %entry ], [ %Or, %bb1 ]
  %Ld = load i8, i8* inttoptr (i64 8 to i8*), align 8
  %And1 = and i8 %Ld, -128
  %And2 = and i8 %P, 127
  %Or = or i8 %And2, %And1
  %C = icmp sgt i8 %Or, -1
  br i1 %C, label %bb1, label %exit

exit:
  %res = zext i1 %C to i32
  ret i32 %res
}

All the bits of %And2 are undef except the sign bit which is used by the icmp.
CorrelatedValuePropagation incorrectly replaces %And2 with %P which makes the
sign bit undefined.

This is observable at llvmorg-10.0.0-rc5 (3562703 / March 19), without the
bootstrap. The problem however (at least with my reduced test case) goes away
with 4878aa3 (March 14). That commit seems to be related exactly to undef
constants in this context. I don't know if that eliminates this bug, or if it
just gets hidden.

./bin/opt -S -mtriple=s390x-linux-gnu -mcpu=z10 ./tc_corrprop.ll
--correlated-propagation -o -   
; ModuleID = './tc_corrprop.ll'
source_filename = "./tc_corrprop.ll"
target triple = "s390x-unknown-linux-gnu"

define i32 @fun() #0 {
entry:
  br label %bb1

bb1:                                              ; preds = %bb1, %entry
  %P = phi i8 [ undef, %entry ], [ %Or, %bb1 ]
  %Ld = load i8, i8* inttoptr (i64 8 to i8*), align 8
  %And1 = and i8 %Ld, -128
  %Or = or i8 %P, %And1
  %C = icmp sgt i8 %Or, -1
  br i1 %C, label %bb1, label %exit

exit:                                             ; preds = %bb1
  %res = zext i1 %C to i32
  ret i32 0
}

attributes #0 = { "target-cpu"="z10" }</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>