[PATCH] D126503: [SCEV] Use fact that B >u 0 for A <u B in applyLoopGuards.

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 29 21:31:25 PDT 2022


mkazantsev added a comment.

I was thinking of smth like

  define void @test_chceks_in_loop(i32* nocapture %a, i64 %i, i64 %N) {
  entry:
    br label loop
  
  loop:
    %iv = phi i64 [ %iv.next, %loop.be ], [ 0, %entry]
    %c.1 = icmp ult i64 %N, 12
    br i1 %c.1, label %loop.guarded.1, label %exit
  
  loop.guarded.1:
    %c.2 = icmp ult i64 %i, %N
    br i1 %c.2, label %loop, label %exit
  
  loop.guarded.2:
    %idx = getelementptr inbounds i32, i32* %a, i64 %iv
    store i32 1, i32* %idx, align 4
    %iv.next = add nuw nsw i64 %iv, 1
    %exitcond = icmp eq i64 %iv, %i
    br i1 %exitcond, label %exit, label %loop
  
  exit:
    ret void
  }

Normally I'd expect this checks would be hoisted/unswitched out, but if not, maybe it also makes sense to make it work.



================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:14481
       RewrittenRHS =
           getSMinExpr(RewrittenLHS, getMinusSCEV(RHS, getOne(RHS->getType())));
       break;
----------------
I think there should be (maybe not such useful, but still) a symmetrical signed case with `SINT_MIN+1` instead of `1`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126503/new/

https://reviews.llvm.org/D126503



More information about the llvm-commits mailing list