UseListOrder: Handle self-users
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 31 Jul 2014 18:33:12 +0000 (18:33 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 31 Jul 2014 18:33:12 +0000 (18:33 +0000)
Correctly sort self-users (such as PHI nodes).  I added a targeted test
in `test/Bitcode/use-list-order.ll` and the final missing RUN line to
tests in `test/Assembly`.

This is part of PR5680.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214417 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Writer/ValueEnumerator.cpp
test/Assembler/2002-08-22-DominanceProblem.ll
test/Bitcode/use-list-order.ll

index 2ac53fea8a98bc9ad1e9a6266ac59e6488ff1c3c..4ed739ebe4abe72b5752ab929170ff60765f274f 100644 (file)
@@ -166,13 +166,13 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
 
     // If ID is 4, then expect: 7 6 5 1 2 3.
     if (LID < RID) {
-      if (RID < ID)
+      if (RID <= ID)
         if (!IsGlobalValue) // GlobalValue uses don't get reversed.
           return true;
       return false;
     }
     if (RID < LID) {
-      if (LID < ID)
+      if (LID <= ID)
         if (!IsGlobalValue) // GlobalValue uses don't get reversed.
           return false;
       return true;
@@ -180,7 +180,7 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
 
     // LID and RID are equal, so we have different operands of the same user.
     // Assume operands are added in order for all instructions.
-    if (LID < ID)
+    if (LID <= ID)
       if (!IsGlobalValue) // GlobalValue uses don't get reversed.
         return LU->getOperandNo() < RU->getOperandNo();
     return LU->getOperandNo() > RU->getOperandNo();
index 0dc192df2356328eec53f942f8737c652d0d1af1..4097f0ab6298255b4b8fc1d5d8be1886f2475868 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: llvm-as %s -o /dev/null
+; RUN: verify-uselistorder %s -preserve-bc-use-list-order -num-shuffles=5
 
 ; Dominance relationships is not calculated correctly for unreachable blocks,
 ; which causes the verifier to barf on this input.
index 3d3a06ca9de3e3fb6177a5dc021745ca5400a37f..293650f4082bc7348f54ff78773ee843f0a332be 100644 (file)
@@ -118,3 +118,16 @@ entry:
   %local = load i4* @globalAndFunction
   ret i4 %local
 }
+
+; Check for when an instruction is its own user.
+define void @selfUser() {
+entry:
+  ret void
+
+loop1:
+  br label %loop2
+
+loop2:
+  %var = phi i32 [ %var, %loop1 ], [ %var, %loop2 ]
+  br label %loop1
+}