[llvm] [polly] [SCEV] Infer addrec nowrap flags during range analysis (PR #202964)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 03:42:59 PDT 2026


================
@@ -15,7 +15,8 @@ define void @foo() {
 ; CHECK-NEXT:    br label [[BB3:%.*]]
 ; CHECK:       bb3:
 ; CHECK-NEXT:    [[TMP6:%.*]] = load i8, ptr getelementptr inbounds nuw (i8, ptr @global, i64 1), align 1
-; CHECK-NEXT:    br i1 false, label [[BB7:%.*]], label [[BB11:%.*]]
+; CHECK-NEXT:    [[TMP5:%.*]] = icmp ugt ptr getelementptr (i8, ptr @global, i64 1), getelementptr (i8, ptr @global, i64 500)
+; CHECK-NEXT:    br i1 [[TMP5]], label [[BB7:%.*]], label [[BB11:%.*]]
----------------
nikic wrote:

It looks like previously this got optimized because we break the loop backedge based on the exit below, and when we replace the header phi with the preheader value we simplify all users, including this icmp.

Now we end up triggering the makeIVComparisonInvariant() fold first, which replaces the operand with a constant, so it's no longer part of the use-def chain for the header phi and doesn't get simplified.

So I think this is harmless perturbation. The icmp will get folded by subsequent passes, and I don't think we care about folding this degenerate case as early as possible.

https://github.com/llvm/llvm-project/pull/202964


More information about the llvm-commits mailing list