When building SCEV expressions for the loop: w7 = w1; r7 = (zext32 r1) w1 = w7; r1 = (zext32 (zext32 r1)) w1 += 2; r1 = (zext32 (+ (zext32 (zext32 r1)) 2)) Computed SCEV expression for r1: (zext32 (linear r1 2)) Substituting this into r7's expression at the latch: (zext32 (zext32 (linear r1 2))) Without (zext32 (zext32 X)) -> (zext32 X) simplification rule the latch would not be recognized as linear and header_count won't be computed. Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/progs/verifier_scev.c | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_scev.c b/tools/testing/selftests/bpf/progs/verifier_scev.c index 39603c8bf083..37434efd1490 100644 --- a/tools/testing/selftests/bpf/progs/verifier_scev.c +++ b/tools/testing/selftests/bpf/progs/verifier_scev.c @@ -3710,4 +3710,31 @@ __naked void dominating_exit_bounds_count(void) " ::: __clobber_all); } +/* + * The counter is copied to a callee-saved register for the call and the copy is compared. + */ +SEC("xdp") +__success +__log_level(2) +__flag(BPF_F_TEST_STATE_FREQ) +__msg(" scev at latch 5:") +__msg(" r7=(zext32 r1) / (zext32 (linear r1 2))") +__msg("loop header at 1, header_count is 100 ") +__msg("loop header at 1, widening r1 to 0..198 step 2") +__naked void post_cond_jlt32_copy(void) +{ + asm volatile (" \ + w1 = 0; \ +1: w7 = w1; \ + call %[bpf_get_prandom_u32]; \ + w1 = w7; \ + w1 += 2; \ + if w7 < 198 goto 1b; \ + r0 = 0; \ + exit; \ +" : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + char _license[] SEC("license") = "GPL"; -- 2.56.0