[llvm] 60984f5 - [InstCombine] Preserve all gep flags in gep of exact div fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 19 05:33:52 PDT 2024
Author: Nikita Popov
Date: 2024-06-19T14:33:43+02:00
New Revision: 60984f5be90d3f0378d739792adbd4c5e3dcc0e2
URL: https://github.com/llvm/llvm-project/commit/60984f5be90d3f0378d739792adbd4c5e3dcc0e2
DIFF: https://github.com/llvm/llvm-project/commit/60984f5be90d3f0378d739792adbd4c5e3dcc0e2.diff
LOG: [InstCombine] Preserve all gep flags in gep of exact div fold
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/getelementptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index d926b1f3f568f..a9c994f8076b2 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2941,10 +2941,9 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
m_SpecificInt(countr_zero(TyAllocSize)))))) ||
match(GEP.getOperand(1),
m_Exact(m_IDiv(m_Value(V), m_SpecificInt(TyAllocSize))))) {
- GetElementPtrInst *NewGEP = GetElementPtrInst::Create(
- Builder.getInt8Ty(), GEP.getPointerOperand(), V);
- NewGEP->setIsInBounds(GEP.isInBounds());
- return NewGEP;
+ return GetElementPtrInst::Create(Builder.getInt8Ty(),
+ GEP.getPointerOperand(), V,
+ GEP.getNoWrapFlags());
}
}
}
diff --git a/llvm/test/Transforms/InstCombine/getelementptr.ll b/llvm/test/Transforms/InstCombine/getelementptr.ll
index a842484c25a86..722ced1f6abb1 100644
--- a/llvm/test/Transforms/InstCombine/getelementptr.ll
+++ b/llvm/test/Transforms/InstCombine/getelementptr.ll
@@ -1566,6 +1566,16 @@ define ptr @gep_sdiv_inbounds(ptr %p, i64 %off) {
ret ptr %ptr
}
+define ptr @gep_sdiv_nuw(ptr %p, i64 %off) {
+; CHECK-LABEL: @gep_sdiv_nuw(
+; CHECK-NEXT: [[PTR:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[OFF:%.*]]
+; CHECK-NEXT: ret ptr [[PTR]]
+;
+ %index = sdiv exact i64 %off, 7
+ %ptr = getelementptr nuw %struct.C, ptr %p, i64 %index
+ ret ptr %ptr
+}
+
define ptr @gep_ashr(ptr %p, i64 %off) {
; CHECK-LABEL: @gep_ashr(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[OFF:%.*]]
More information about the llvm-commits
mailing list