[llvm] [IndVars] Use context for proving same sign (PR #181093)

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 12 09:09:11 PST 2026


================
@@ -827,11 +827,13 @@ define void @func_22(ptr %length.ptr) {
 ; CHECK-NEXT:    [[ENTRY_COND:%.*]] = icmp sgt i32 [[LENGTH]], 1
 ; CHECK-NEXT:    br i1 [[ENTRY_COND]], label [[LOOP_PREHEADER:%.*]], label [[LEAVE:%.*]]
 ; CHECK:       loop.preheader:
+; CHECK-NEXT:    [[TMP0:%.*]] = add nuw nsw i32 [[LENGTH]], 1
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
 ; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[IV_INC:%.*]], [[BE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
 ; CHECK-NEXT:    [[IV_INC]] = add nuw nsw i32 [[IV]], 1
-; CHECK-NEXT:    br i1 true, label [[BE]], label [[LEAVE_LOOPEXIT:%.*]]
+; CHECK-NEXT:    [[EXITCOND1:%.*]] = icmp ne i32 [[IV]], [[TMP0]]
+; CHECK-NEXT:    br i1 [[EXITCOND1]], label [[BE]], label [[LEAVE_LOOPEXIT:%.*]]
----------------
xortator wrote:

Ok it seems that problem exists even without my patch. See test:

https://godbolt.org/z/YEMbK5dPf

I just manually replaced `sle` with `ule` in backedge and now it fails to eliminate the range check in master. The replacement is equivalent because `lim` is non-negative as well as `IV` and `IV.next`. 

I propose to waive this and fix this separately.

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


More information about the llvm-commits mailing list