Stabilize the order of live intervals in the priority_queue used by the
authorBob Wilson <bob.wilson@apple.com>
Sat, 5 Sep 2009 01:19:16 +0000 (01:19 +0000)
committerBob Wilson <bob.wilson@apple.com>
Sat, 5 Sep 2009 01:19:16 +0000 (01:19 +0000)
linear scan reg alloc.  This fixes a problem I ran into where extracting
a function from a larger file caused the generated code to change (masking
the problem I was trying to debug) because the allocator behaved differently.

This changes the results for two X86 regression checks.  stack-color-with-reg
is improved, with one less instruction, but pr3495 is worse, with one more
copy.  As far as I can tell, these tests were just getting lucky or unlucky,
so I've changed the expected results.

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

include/llvm/CodeGen/LiveInterval.h
test/CodeGen/X86/pr3495.ll
test/CodeGen/X86/stack-color-with-reg.ll

index 921c5572b9c198eb2850ce1b9618a7cfec59c3be..2a8c2c88418ac210c1566fccf8a0bec0194ac272 100644 (file)
@@ -774,7 +774,10 @@ namespace llvm {
     void ComputeJoinedWeight(const LiveInterval &Other);
 
     bool operator<(const LiveInterval& other) const {
     void ComputeJoinedWeight(const LiveInterval &Other);
 
     bool operator<(const LiveInterval& other) const {
-      return beginIndex() < other.beginIndex();
+      const MachineInstrIndex &thisIndex = beginIndex();
+      const MachineInstrIndex &otherIndex = other.beginIndex();
+      return (thisIndex < otherIndex ||
+              (thisIndex == otherIndex && reg < other.reg));
     }
 
     void print(raw_ostream &OS, const TargetRegisterInfo *TRI = 0) const;
     }
 
     void print(raw_ostream &OS, const TargetRegisterInfo *TRI = 0) const;
index ca6204c101e9a3e21de1c1e0df20be440edb289b..368c38ce12b2210ea73b09d9777690bb90af7d83 100644 (file)
@@ -1,6 +1,6 @@
-; RUN: llvm-as < %s | llc -march=x86 -stats |& grep {Number of reloads omited} | grep 2
-; RUN: llvm-as < %s | llc -march=x86 -stats |& not grep {Number of available reloads turned into copies}
-; RUN: llvm-as < %s | llc -march=x86 -stats |& grep {Number of machine instrs printed} | grep 39
+; RUN: llvm-as < %s | llc -march=x86 -stats |& grep {Number of reloads omited} | grep 1
+; RUN: llvm-as < %s | llc -march=x86 -stats |& grep {Number of available reloads turned into copies} | grep 1
+; RUN: llvm-as < %s | llc -march=x86 -stats |& grep {Number of machine instrs printed} | grep 40
 ; PR3495
 ; The loop reversal kicks in once here, resulting in one fewer instruction.
 
 ; PR3495
 ; The loop reversal kicks in once here, resulting in one fewer instruction.
 
index 114e9bf48d73ed525a88bb510049be0c7e91e21a..604bd4fed82157f965119607f56608f6dd25945e 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin10 -relocation-model=pic -disable-fp-elim -color-ss-with-regs -stats -info-output-file - > %t
 ; RUN:   grep stackcoloring %t | grep "loads eliminated" 
 ; RUN:   grep stackcoloring %t | grep "stack slot refs replaced with reg refs"  | grep 5
 ; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin10 -relocation-model=pic -disable-fp-elim -color-ss-with-regs -stats -info-output-file - > %t
 ; RUN:   grep stackcoloring %t | grep "loads eliminated" 
 ; RUN:   grep stackcoloring %t | grep "stack slot refs replaced with reg refs"  | grep 5
-; RUN:   grep asm-printer %t   | grep 182
+; RUN:   grep asm-printer %t   | grep 181
 
        type { [62 x %struct.Bitvec*] }         ; type %0
        type { i8* }            ; type %1
 
        type { [62 x %struct.Bitvec*] }         ; type %0
        type { i8* }            ; type %1