On Wed, 2024-06-12 at 18:38 -0700, Alexei Starovoitov wrote: > From: Alexei Starovoitov <ast@xxxxxxxxxx> > > Compilers can generate the code > r1 = r2 > r1 += 0x1 > if r2 < 1000 goto ... > use knowledge of r2 range in subsequent r1 operations > > So remember constant delta between r2 and r1 and update r1 after 'if' condition. > > Unfortunately LLVM still uses this pattern for loops with 'can_loop' construct: > for (i = 0; i < 1000 && can_loop; i++) > > The "undo" pass was introduced in LLVM > https://reviews.llvm.org/D121937 > to prevent this optimization, but it cannot cover all cases. > Instead of fighting middle end optimizer in BPF backend teach the verifier > about this pattern. > > Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> > --- Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx>