Repository navigation
[InlineSpiller] Hoist spills only when all of its subranges are available - #177703
Conversation
|
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-backend-hexagon Author: Min-Yih Hsu (mshockwave) ChangesA potential solution to #176001 I still need to write up what I think happened to that issue. And add test cases to this PR. 2 Files Affected:
diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index 68370303a3aef..07a1581da2b1a 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -1409,8 +1409,11 @@ bool HoistSpillHelper::isSpillCandBB(LiveInterval &OrigLI, VNInfo &OrigVNI,
for (const Register &SibReg : Siblings) {
LiveInterval &LI = LIS.getInterval(SibReg);
- VNInfo *VNI = LI.getVNInfoAt(Idx);
- if (VNI) {
+ if (!LI.getVNInfoAt(Idx))
+ continue;
+ if (all_of(LI.subranges(), [&](const LiveInterval::SubRange &SR) {
+ return SR.getVNInfoAt(Idx);
+ })) {
LiveReg = SibReg;
return true;
}
diff --git a/llvm/test/CodeGen/Hexagon/regalloc-bad-undef.mir b/llvm/test/CodeGen/Hexagon/regalloc-bad-undef.mir
index 019d593c34948..04a19868b0671 100644
--- a/llvm/test/CodeGen/Hexagon/regalloc-bad-undef.mir
+++ b/llvm/test/CodeGen/Hexagon/regalloc-bad-undef.mir
@@ -152,12 +152,12 @@ body: |
; CHECK-NEXT: renamable $d0 = A2_tfrpi 2
; CHECK-NEXT: renamable $d13 = A2_tfrpi -1
; CHECK-NEXT: renamable $d13 = S2_asl_r_p_acc killed renamable $d13, killed renamable $d0, renamable $r4
- ; CHECK-NEXT: S2_storerd_io %stack.0, 0, renamable $d2 :: (store (s64) into %stack.0)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.1.for.body:
; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
- ; CHECK-NEXT: liveins: $d8:0x0000000000000001, $d13, $r20
+ ; CHECK-NEXT: liveins: $d2:0x0000000000000002, $d8:0x0000000000000001, $d13, $r20
; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: S2_storerd_io %stack.0, 0, renamable $d2 :: (store (s64) into %stack.0)
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def dead $r29, implicit-def dead $r30, implicit $r31, implicit $r30, implicit $r29
; CHECK-NEXT: J2_call @lrand48, implicit-def dead $d0, implicit-def dead $d1, implicit-def dead $d2, implicit-def dead $d3, implicit-def dead $d4, implicit-def dead $d5, implicit-def dead $d6, implicit-def dead $d7, implicit-def dead $r28, implicit-def dead $r31, implicit-def dead $p0, implicit-def dead $p1, implicit-def dead $p2, implicit-def dead $p3, implicit-def dead $m0, implicit-def dead $m1, implicit-def dead $lc0, implicit-def dead $lc1, implicit-def dead $sa0, implicit-def dead $sa1, implicit-def dead $usr, implicit-def $usr_ovf, implicit-def dead $cs0, implicit-def dead $cs1, implicit-def dead $w0, implicit-def dead $w1, implicit-def dead $w2, implicit-def dead $w3, implicit-def dead $w4, implicit-def dead $w5, implicit-def dead $w6, implicit-def dead $w7, implicit-def dead $w8, implicit-def dead $w9, implicit-def dead $w10, implicit-def dead $w11, implicit-def dead $w12, implicit-def dead $w13, implicit-def dead $w14, implicit-def dead $w15, implicit-def dead $q0, implicit-def dead $q1, implicit-def dead $q2, implicit-def dead $q3, implicit-def $r0
; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def dead $r29, implicit-def dead $r30, implicit-def dead $r31, implicit $r29
@@ -180,7 +180,7 @@ body: |
; CHECK-NEXT: J2_call @lrand48, implicit-def dead $d0, implicit-def dead $d1, implicit-def dead $d2, implicit-def dead $d3, implicit-def dead $d4, implicit-def dead $d5, implicit-def dead $d6, implicit-def dead $d7, implicit-def dead $r28, implicit-def dead $r31, implicit-def dead $p0, implicit-def dead $p1, implicit-def dead $p2, implicit-def dead $p3, implicit-def dead $m0, implicit-def dead $m1, implicit-def dead $lc0, implicit-def dead $lc1, implicit-def dead $sa0, implicit-def dead $sa1, implicit-def dead $usr, implicit-def $usr_ovf, implicit-def dead $cs0, implicit-def dead $cs1, implicit-def dead $w0, implicit-def dead $w1, implicit-def dead $w2, implicit-def dead $w3, implicit-def dead $w4, implicit-def dead $w5, implicit-def dead $w6, implicit-def dead $w7, implicit-def dead $w8, implicit-def dead $w9, implicit-def dead $w10, implicit-def dead $w11, implicit-def dead $w12, implicit-def dead $w13, implicit-def dead $w14, implicit-def dead $w15, implicit-def dead $q0, implicit-def dead $q1, implicit-def dead $q2, implicit-def dead $q3
; CHECK-NEXT: renamable $d2 = L2_loadrd_io %stack.0, 0 :: (load (s64) from %stack.0)
; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def dead $r29, implicit-def dead $r30, implicit-def dead $r31, implicit $r29
- ; CHECK-NEXT: renamable $d0 = S2_asl_r_p killed renamable $d11, killed renamable $r4
+ ; CHECK-NEXT: renamable $d0 = S2_asl_r_p killed renamable $d11, renamable $r4
; CHECK-NEXT: renamable $d1 = COPY renamable $d13
; CHECK-NEXT: renamable $d1 = S2_lsr_i_p_and killed renamable $d1, killed renamable $d9, 9
; CHECK-NEXT: renamable $d0 = S2_asl_i_p_and killed renamable $d0, killed renamable $d12, 42
@@ -192,7 +192,7 @@ body: |
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.2.if.end82:
; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.1(0x40000000)
- ; CHECK-NEXT: liveins: $d8:0x0000000000000001, $d13, $r20
+ ; CHECK-NEXT: liveins: $d2:0x0000000000000002, $d8:0x0000000000000001, $d13, $r20
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: renamable $r20 = A2_addi killed renamable $r20, -1
; CHECK-NEXT: renamable $p0 = C2_cmpeqi renamable $r20, 0
|
| if (!LI.getVNInfoAt(Idx)) | ||
| continue; | ||
| if (all_of(LI.subranges(), [&](const LiveInterval::SubRange &SR) { | ||
| return SR.getVNInfoAt(Idx); |
There was a problem hiding this comment.
Does it need to verify the value numbers are the same?
There was a problem hiding this comment.
If you're suggesting checking against OrigVNI, my understanding is that it might lead to false negative: the sibling registers here are split from the original register. And when a new split register interval is created, its value number always starts from zero.
For example, a live interval %438 [2792r,3104r:0)[3688r,6816r:1) 0@2792r 1@3688ris split into two sibling registers
%438 [2792r,3104r:0) 0@2792r%439 [3688r,6816r:0) 0@3688r
Let's say the OrigVNI (which is a pre-split VNI) is 1@3688r here, and it's checking against a sibling VNI (which is a post-split VNI) of 0@3688r. Even their value numbers are different, they're actually referring to the same value. It suffices to check just the slot index because I think the splitter creates two new LiveIntervals with different value numbers only if they have disjoint slot index ranges.
99eba23 to
2745bb7
Compare
|
I think this PR is ready for review. |
You can test this locally with the following command:git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef([^a-zA-Z0-9_-]|$)|UndefValue::get)' 'HEAD~1' HEAD llvm/test/CodeGen/RISCV/pr176001.ll llvm/lib/CodeGen/InlineSpiller.cppThe following files introduce new uses of undef:
Undef is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields In tests, avoid using For example, this is considered a bad practice: define void @fn() {
...
br i1 undef, ...
}Please use the following instead: define void @fn(i1 %cond) {
...
br i1 %cond, ...
}Please refer to the Undefined Behavior Manual for more information. |
|
@arsenm do you have any other comments? |
|
/cherry-pick 75f03a6 |
|
/pull-request #178737 |
…able (llvm#177703) Context: llvm#176001 (comment) When we're hoisting a spill to another block, and storing one of its sibling values there instead, we need to make sure all sub ranges of that sibling value is alive at the insertion point. Otherwise, we might accidentally store compromised subranges values back to the spill slot. (cherry picked from commit 75f03a6)
…able (llvm#177703) Context: llvm#176001 (comment) When we're hoisting a spill to another block, and storing one of its sibling values there instead, we need to make sure all sub ranges of that sibling value is alive at the insertion point. Otherwise, we might accidentally store compromised subranges values back to the spill slot.
Context: #176001 (comment)
When we're hoisting a spill to another block, and storing one of its sibling values there instead, we need to make sure all sub ranges of that sibling value is alive at the insertion point. Otherwise, we might accidentally store compromised subranges values back to the spill slot.