[llvm] 6efba06 - [InstCombine] Preserve all gep flags in dependent IV fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 19 03:22:00 PDT 2024
Author: Nikita Popov
Date: 2024-06-19T12:21:52+02:00
New Revision: 6efba06123c96fe7d51cfbb0801407dd3d952839
URL: https://github.com/llvm/llvm-project/commit/6efba06123c96fe7d51cfbb0801407dd3d952839
DIFF: https://github.com/llvm/llvm-project/commit/6efba06123c96fe7d51cfbb0801407dd3d952839.diff
LOG: [InstCombine] Preserve all gep flags in dependent IV fold
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
llvm/test/Transforms/InstCombine/dependent-ivs.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 0ee9bc5fecb72..86411320ab248 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -1421,7 +1421,7 @@ static Value *foldDependentIVs(PHINode &PN, IRBuilderBase &Builder) {
if (!BO) {
auto *GEP = cast<GEPOperator>(IvNext);
return Builder.CreateGEP(GEP->getSourceElementType(), Start, Iv2, "",
- cast<GEPOperator>(IvNext)->isInBounds());
+ cast<GEPOperator>(IvNext)->getNoWrapFlags());
}
assert(BO->isCommutative() && "Must be commutative");
diff --git a/llvm/test/Transforms/InstCombine/dependent-ivs.ll b/llvm/test/Transforms/InstCombine/dependent-ivs.ll
index c2cff61ecb388..e3207daefee09 100644
--- a/llvm/test/Transforms/InstCombine/dependent-ivs.ll
+++ b/llvm/test/Transforms/InstCombine/dependent-ivs.ll
@@ -537,8 +537,39 @@ exit:
ret void
}
-define void @ptr_iv_no_inbounds(ptr %base, i64 %end) {
-; CHECK-LABEL: define void @ptr_iv_no_inbounds(
+define void @ptr_iv_nuw(ptr %base, i64 %end) {
+; CHECK-LABEL: define void @ptr_iv_nuw(
+; CHECK-SAME: ptr [[BASE:%.*]], i64 [[END:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[IV_PTR:%.*]] = getelementptr nuw i8, ptr [[BASE]], i64 [[IV]]
+; CHECK-NEXT: call void @use.p0(ptr [[IV_PTR]])
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[IV_NEXT]], [[END]]
+; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %loop
+
+loop:
+ %iv.ptr = phi ptr [ %iv.ptr.next, %loop ], [ %base, %entry ]
+ %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]
+ call void @use.p0(ptr %iv.ptr)
+ %iv.next = add nuw nsw i64 %iv, 4
+ %iv.ptr.next = getelementptr nuw i8, ptr %base, i64 %iv.next
+ %cmp = icmp eq i64 %iv.next, %end
+ br i1 %cmp, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+define void @ptr_iv_no_flags(ptr %base, i64 %end) {
+; CHECK-LABEL: define void @ptr_iv_no_flags(
; CHECK-SAME: ptr [[BASE:%.*]], i64 [[END:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP:%.*]]
More information about the llvm-commits
mailing list