<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 - Phi operands are not sorted in predecessor order"
   href="https://bugs.llvm.org/show_bug.cgi?id=32981">32981</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Phi operands are not sorted in predecessor order
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dberlin@dberlin.org, llvm-bugs@lists.llvm.org, su@cs.ucdavis.edu
          </td>
        </tr></table>
      <p>
        <div>
        <pre>; ModuleID = 'small.ll'
source_filename = "meh.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@a = common global i16 0, align 2
@b = common global [1 x i16] zeroinitializer, align 2

; Function Attrs: nounwind uwtable
define i32 @main() #0 {
entry:
  %0 = load i16, i16* @a, align 2, !tbaa !1
  %conv = sext i16 %0 to i32
  %neg = xor i32 %conv, -1
  %conv1 = trunc i32 %neg to i16
  %conv3 = zext i16 %conv1 to i32
  %cmp = icmp slt i32 %conv, %conv3
  br i1 %cmp, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  store i16 %conv1, i16* @a, align 2, !tbaa !1
  br label %if.end

if.end:                                           ; preds = %if.then, %entry
  %c.0 = phi i16 [ %0, %if.then ], [ %conv1, %entry ]
  %1 = load i16, i16* @a, align 2, !tbaa !1
  %tobool = icmp ne i16 %1, 0
  br i1 %tobool, label %if.then8, label %if.end9

if.then8:                                         ; preds = %if.end
  %idxprom = zext i16 %c.0 to i64
  %arrayidx = getelementptr inbounds [1 x i16], [1 x i16]* @b, i64 0, i64
%idxprom
  %2 = load i16, i16* %arrayidx, align 2, !tbaa !1
  store i16 %2, i16* @a, align 2, !tbaa !1
  br label %if.end9

if.end9:                                          ; preds = %if.then8, %if.end
  ret i32 0
}

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1

attributes #0 = { nounwind uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "no-frame-pointer-elim"="false"
"no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { argmemonly nounwind }

!llvm.ident = !{!0}

!0 = !{!"clang version 5.0.0 (trunk 302523) (llvm/trunk 302532)"}
!1 = !{!2, !2, i64 0}
!2 = !{!"short", !3, i64 0}
!3 = !{!"omnipotent char", !4, i64 0}
!4 = !{!"Simple C/C++ TBAA"}


Given the following IR, running jump-threading on it introduces a new PHI which
operands have an order inconsistent with the one of the original PHI.

[davide@cupiditate bin]$ ./opt -jump-threading prejump.ll
-preserve-ll-uselistorder -S -o - | grep phi
  %1 = phi i16 [ %.pr, %if.endthread-pre-split ], [ %conv1, %if.then ]
  %c.0 = phi i16 [ %0, %if.then ], [ %conv1, %if.endthread-pre-split ]
[davide@cupiditate bin]$ cat prejump.ll |grep phi
  %c.0 = phi i16 [ %0, %if.then ], [ %conv1, %entry ]

Found out while looking at a report from Zhendong Su. Looking at this.</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>