Commit bceec8e
[BPF] Reset machine register kill mark in BPFMISimplifyPatchable
When LLVM is build with `LLVM_ENABLE_EXPENSIVE_CHECKS=ON` option
the following C code snippet:
struct t {
unsigned long a;
} __attribute__((preserve_access_index));
void foo(volatile struct t *t, volatile unsigned long *p) {
*p = t->a;
*p = t->a;
}
Causes an assertion:
$ clang -g -O2 -c --target=bpf -mcpu=v2 t2.c -o /dev/null
# After BPF PreEmit SimplifyPatchable
# Machine code for function foo: IsSSA, TracksLiveness
Function Live Ins: $r1 in %0, $r2 in %1
bb.0.entry:
liveins: $r1, $r2
DBG_VALUE $r1, $noreg, !"t", !DIExpression()
DBG_VALUE $r2, $noreg, !"p", !DIExpression()
%1:gpr = COPY $r2
DBG_VALUE %1:gpr, $noreg, !"p", !DIExpression()
%0:gpr = COPY $r1
DBG_VALUE %0:gpr, $noreg, !"t", !DIExpression()
%2:gpr = LD_imm64 @"llvm.t:0:0$0:0"
%4:gpr = ADD_rr %0:gpr(tied-def 0), killed %2:gpr
%5:gpr = CORE_LD 344, %0:gpr, @"llvm.t:0:0$0:0"
STD killed %5:gpr, %1:gpr, 0
%7:gpr = ADD_rr %0:gpr(tied-def 0), killed %2:gpr
%8:gpr = CORE_LD 344, %0:gpr, @"llvm.t:0:0$0:0"
STD killed %8:gpr, %1:gpr, 0
RET
# End machine code for function foo.
*** Bad machine code: Using a killed virtual register ***
- function: foo
- basic block: %bb.0 entry (0x6210000e6690)
- instruction: %7:gpr = ADD_rr %0:gpr(tied-def 0), killed %2:gpr
- operand 2: killed %2:gpr
This happens because of the way
BPFMISimplifyPatchable::processDstReg() updates second operand of the
`ADD_rr` instruction. Code before `BPFMISimplifyPatchable`:
.-> %2:gpr = LD_imm64 @"llvm.t:0:0$0:0"
|
|`----------------.
| %3:gpr = LDD %2:gpr, 0
| %4:gpr = ADD_rr %0:gpr(tied-def 0), killed %3:gpr <--- (1)
| %5:gpr = LDD killed %4:gpr, 0 ^^^^^^^^^^^^^
| STD killed %5:gpr, %1:gpr, 0 this is updated
`----------------.
%6:gpr = LDD %2:gpr, 0
%7:gpr = ADD_rr %0:gpr(tied-def 0), killed %6:gpr <--- (2)
%8:gpr = LDD killed %7:gpr, 0 ^^^^^^^^^^^^^
STD killed %8:gpr, %1:gpr, 0 this is updated
Instructions (1) and (2) would be updated to:
ADD_rr %0:gpr(tied-def 0), killed %2:gpr
The `killed` mark is inherited from machine operands `killed %3:gpr`
and `killed %6:gpr` which are updated inplace by `processDstReg()`.
This commit updates `processDstReg()` reset kill marks for updated
machine operands to keep liveness information conservatively correct.
Differential Revision: https://reviews.llvm.org/D157805
(cherry picked from commit 27026fe)1 parent de0f8c2 commit bceec8e
File tree
2 files changed
+146
-1
lines changed- llvm
- lib/Target/BPF
- test/CodeGen/BPF/CORE
2 files changed
+146
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
211 | 233 | | |
| 234 | + | |
| 235 | + | |
212 | 236 | | |
213 | 237 | | |
214 | 238 | | |
| |||
Lines changed: 121 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
0 commit comments