[llvm] [indvars] Allow widenWithVariantUse to succeed without extend users (PR #71557)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 07:53:25 PST 2023


================
@@ -365,16 +364,15 @@ define void @zext_postinc_offset_constant_one(ptr %A, i32 %start) {
 ; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
 ; CHECK:       for.body:
 ; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[TMP0]], [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
-; CHECK-NEXT:    [[J_016_US:%.*]] = phi i32 [ [[INC_US:%.*]], [[FOR_BODY]] ], [ [[START]], [[FOR_BODY_PREHEADER]] ]
 ; CHECK-NEXT:    [[TMP1:%.*]] = trunc i64 [[INDVARS_IV]] to i32
 ; CHECK-NEXT:    [[ADD_US:%.*]] = add i32 [[TMP1]], 1
 ; CHECK-NEXT:    [[IDXPROM_US:%.*]] = zext i32 [[ADD_US]] to i64
 ; CHECK-NEXT:    [[ARRAYIDX_US:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IDXPROM_US]]
 ; CHECK-NEXT:    tail call void @use_ptr(ptr [[ARRAYIDX_US]])
-; CHECK-NEXT:    [[INC_US]] = add nsw i32 [[J_016_US]], -1
-; CHECK-NEXT:    [[CMP2_US:%.*]] = icmp ugt i32 [[INC_US]], 6
+; CHECK-NEXT:    [[TMP2:%.*]] = add nsw i64 [[INDVARS_IV]], 4294967295
----------------
preames wrote:

The key fact is that we have a loop entry condition which proves both that start is non-negative, and that start -1 is still positive.  Given this precondition trunc(zext(start)+4294967295) == start-1.  Given we know we exit without the IV every becoming negative (in either 32 or 64), this should be the same.  

In general, this transform relies on the high bits of the addrec being don't care *except* for the identified users it visits and proves that the result of the *user* is unchanged by the possible change in the high bits.  



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


More information about the llvm-commits mailing list