From: Alexei Starovoitov The prog is what clang emits for 'for (i = 0; i < 17; i++)'. The latch (the jump back to the loop head) tests a 32-bit copy of the counter. The prog makes the copy before the increment: 1: w1 = w6 w6 += 1 if w1 < 16 goto 1b The test expects 'header_count is 17'. Without "bpf: Simplify (zext32 (zext32 x)) in scalar evolution" the message is 'non-linear latch'. Signed-off-by: Alexei Starovoitov --- .../selftests/bpf/progs/verifier_scev.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_scev.c b/tools/testing/selftests/bpf/progs/verifier_scev.c index bd632951492a..5a7c32ce1c6c 100644 --- a/tools/testing/selftests/bpf/progs/verifier_scev.c +++ b/tools/testing/selftests/bpf/progs/verifier_scev.c @@ -1411,6 +1411,27 @@ __naked void widened_reg_is_not_linked(void) : __clobber_all); } +/* + * for (i = 0; i < 17; i++), the way clang does it: the copy that is compared is made before + * the increment, all in 32 bit: (zext32 (zext32 (linear r6 1))). + */ +SEC("socket") +__success +__log_level(2) +__msg("loop header at 1, header_count is 17") +__naked void latch_tests_a_32bit_copy(void) +{ + asm volatile ( + "w6 = 0;" +"1:" + "w1 = w6;" + "w6 += 1;" + "if w1 < 16 goto 1b;" + "r0 = 0;" + "exit;" + ::: __clobber_all); +} + const volatile __u32 rodata_bound = 10; /* for (i = 0; i < rodata_bound; i++): the bound is loaded in every iteration. */ -- 2.55.0