[PATCH] D156497: [BPF] Emit UNDEF rather than constant 0
Eduard Zingerman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 18 05:52:55 PDT 2023
eddyz87 added a comment.
By the way, it is still possible to test this using e.g. llc or clang. As noted previously in this thread the default error handler for llc/clang is stateful, so it proceeds the code generation, produces assembly code and returns non-zero error code.
I checked how `UNDEF` is handled, short answer: it disappears and it could replace instructions that use it.
For example:
$ cat t.c
extern void bar(void);
int foo(int a, int b, int c, int d, int e, int f) {
bar();
return a + f;
}
$ clang -O2 --target=bpf -mllvm -print-after=verify,bpf-isel,processimpdefs -c t.c -o - | llvm-objdump -d -
*** IR Dump After Module Verifier (verify) ***
; Function Attrs: nounwind
define dso_local i32 @foo(i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d, i32 noundef %e, i32 noundef %f) local_unnamed_addr #0 {
entry:
%call = tail call i32 @bar() #2
%add = add nsw i32 %f, %a
ret i32 %add
}
t.c:2:5: error: stack arguments are not supported
2 | int foo(int a, int b, int c, int d, int e, int f) {
| ^
# *** IR Dump After BPF DAG->DAG Pattern Instruction Selection (bpf-isel) ***:
# Machine code for function foo: IsSSA, TracksLiveness
bb.0.entry:
ADJCALLSTACKDOWN 0, 0, implicit-def dead $r11, implicit $r11
JAL @bar, implicit-def $r0, implicit-def dead $r1, implicit-def dead $r2, implicit-def dead $r3, implicit-def dead $r4, implicit-def dead $r5, implicit $r11
ADJCALLSTACKUP 0, 0, implicit-def dead $r11, implicit $r11
%5:gpr = COPY $r0
%6:gpr = IMPLICIT_DEF
$r0 = COPY %6:gpr
RET implicit $r0
# End machine code for function foo.
# *** IR Dump After Process Implicit Definitions (processimpdefs) ***:
# Machine code for function foo: IsSSA, TracksLiveness
bb.0.entry:
ADJCALLSTACKDOWN 0, 0, implicit-def dead $r11, implicit $r11
JAL @bar, implicit-def $r0, implicit-def dead $r1, implicit-def dead $r2, implicit-def dead $r3, implicit-def dead $r4, implicit-def dead $r5, implicit $r11
ADJCALLSTACKUP 0, 0, implicit-def dead $r11, implicit $r11
RET implicit undef $r0
# End machine code for function foo.
1 error generated.
0000000000000000 <foo>:
0: 85 10 00 00 ff ff ff ff call -0x1
1: 95 00 00 00 00 00 00 00 exit
Note how `add` instruction disappeared, `processimpdefs` converted uses of `IMPLICIT_DEF` to `undef`, `undef` just peeks some physical register (implicitly defined r0 in this case). The final result looks confusing and will pass verification w/o issues. It looks like `getUNDEF()` would some times be confusing and sometimes lead to verifier errors (although one would need to track back these errors).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156497/new/
https://reviews.llvm.org/D156497
More information about the llvm-commits
mailing list