diff options
author | Nikita Popov <npopov@redhat.com> | 2024-06-19 14:33:01 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-06-19 14:33:43 +0200 |
commit | 60984f5be90d3f0378d739792adbd4c5e3dcc0e2 (patch) | |
tree | 8e91450669e064bd1d8253d624924c4dc580bce5 | |
parent | 781133037387eefa4080aa31c73554cc0452e6e6 (diff) | |
download | llvm-60984f5be90d3f0378d739792adbd4c5e3dcc0e2.zip llvm-60984f5be90d3f0378d739792adbd4c5e3dcc0e2.tar.gz llvm-60984f5be90d3f0378d739792adbd4c5e3dcc0e2.tar.bz2 |
[InstCombine] Preserve all gep flags in gep of exact div fold
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 7 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/getelementptr.ll | 10 |
2 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index d926b1f..a9c994f 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 a842484..722ced1 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:%.*]] |