[llvm] 434a8a0 - [InstCombine] Preserve all gep nowrap flags in PointerReplacer
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 00:30:50 PDT 2024
Author: Nikita Popov
Date: 2024-06-04T09:30:43+02:00
New Revision: 434a8a08a2f26bb30cb30c3f9f6794cf7a190844
URL: https://github.com/llvm/llvm-project/commit/434a8a08a2f26bb30cb30c3f9f6794cf7a190844
DIFF: https://github.com/llvm/llvm-project/commit/434a8a08a2f26bb30cb30c3f9f6794cf7a190844.diff
LOG: [InstCombine] Preserve all gep nowrap flags in PointerReplacer
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/memcpy-addrspace.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 832f89ed0b642..21d5e1dece024 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -391,7 +391,7 @@ void PointerReplacer::replace(Instruction *I) {
GetElementPtrInst::Create(GEP->getSourceElementType(), V, Indices);
IC.InsertNewInstWith(NewI, GEP->getIterator());
NewI->takeName(GEP);
- NewI->setIsInBounds(GEP->isInBounds());
+ NewI->setNoWrapFlags(GEP->getNoWrapFlags());
WorkMap[GEP] = NewI;
} else if (auto *SI = dyn_cast<SelectInst>(I)) {
auto *NewSI = SelectInst::Create(
diff --git a/llvm/test/Transforms/InstCombine/memcpy-addrspace.ll b/llvm/test/Transforms/InstCombine/memcpy-addrspace.ll
index 2ec3994f30fcd..d6624010acb21 100644
--- a/llvm/test/Transforms/InstCombine/memcpy-addrspace.ll
+++ b/llvm/test/Transforms/InstCombine/memcpy-addrspace.ll
@@ -22,6 +22,26 @@ entry:
ret void
}
+; Same as previous test, but with gep nusw nuw instead of inbounds.
+define void @test_load_gep_nusw_nuw(ptr addrspace(1) %out, i64 %x) {
+; CHECK-LABEL: @test_load_gep_nusw_nuw(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr nusw nuw [8 x i32], ptr addrspace(2) @test.data, i64 0, i64 [[X:%.*]]
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(2) [[ARRAYIDX]], align 4
+; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr nusw nuw i32, ptr addrspace(1) [[OUT:%.*]], i64 [[X]]
+; CHECK-NEXT: store i32 [[TMP0]], ptr addrspace(1) [[ARRAYIDX1]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %data = alloca [8 x i32], align 4
+ call void @llvm.memcpy.p0.p2.i64(ptr align 4 %data, ptr addrspace(2) align 4 @test.data, i64 32, i1 false)
+ %arrayidx = getelementptr nusw nuw [8 x i32], ptr %data, i64 0, i64 %x
+ %0 = load i32, ptr %arrayidx, align 4
+ %arrayidx1 = getelementptr nusw nuw i32, ptr addrspace(1) %out, i64 %x
+ store i32 %0, ptr addrspace(1) %arrayidx1, align 4
+ ret void
+}
+
define void @test_load_bitcast_chain(ptr addrspace(1) %out, i64 %x) {
; CHECK-LABEL: @test_load_bitcast_chain(
; CHECK-NEXT: entry:
More information about the llvm-commits
mailing list