Skip to content

Commit feaee8d

Browse files
committed
[InstCombine] Preserve GEP no-wrap flags
1 parent e59b12f commit feaee8d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
537537

538538
GetElementPtrInst *NewGEP = GetElementPtrInst::Create(
539539
GEP->getSourceElementType(), NewPtr, NewOps);
540-
NewGEP->setIsInBounds(GEP->isInBounds());
540+
NewGEP->setNoWrapFlags(GEP->getNoWrapFlags());
541541
return NewGEP;
542542
}
543543
}
@@ -1982,7 +1982,7 @@ static Value *buildNew(Instruction *I, ArrayRef<Value*> NewOps,
19821982
ArrayRef<Value*> Idx = NewOps.slice(1);
19831983
return Builder.CreateGEP(cast<GEPOperator>(I)->getSourceElementType(),
19841984
Ptr, Idx, "",
1985-
cast<GEPOperator>(I)->isInBounds());
1985+
cast<GEPOperator>(I)->getNoWrapFlags());
19861986
}
19871987
}
19881988
llvm_unreachable("failed to rebuild vector instructions");

llvm/test/Transforms/InstCombine/gep-vector-indices.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ define ptr @vector_splat_indices_nxv2i64_ext0_inbounds(ptr %a) {
2626

2727
define ptr @vector_splat_indices_nxv2i64_ext0_nuw(ptr %a) {
2828
; CHECK-LABEL: @vector_splat_indices_nxv2i64_ext0_nuw(
29-
; CHECK-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 16
29+
; CHECK-NEXT: [[RES:%.*]] = getelementptr nuw i8, ptr [[A:%.*]], i64 16
3030
; CHECK-NEXT: ret ptr [[RES]]
3131
;
3232
%tmp = insertelement <vscale x 2 x i64> poison, i64 4, i32 0
@@ -38,7 +38,7 @@ define ptr @vector_splat_indices_nxv2i64_ext0_nuw(ptr %a) {
3838

3939
define ptr @vector_splat_indices_nxv2i64_ext0_nusw(ptr %a) {
4040
; CHECK-LABEL: @vector_splat_indices_nxv2i64_ext0_nusw(
41-
; CHECK-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 16
41+
; CHECK-NEXT: [[RES:%.*]] = getelementptr nusw nuw i8, ptr [[A:%.*]], i64 16
4242
; CHECK-NEXT: ret ptr [[RES]]
4343
;
4444
%tmp = insertelement <vscale x 2 x i64> poison, i64 4, i32 0

llvm/test/Transforms/InstCombine/vec_shuffle.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ define <1 x ptr> @shuffle_gep_inbounds(ptr %x1, ptr %x2) {
277277
define <1 x ptr> @shuffle_gep_nuw(ptr %x1, ptr %x2) {
278278
; CHECK-LABEL: @shuffle_gep_nuw(
279279
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <1 x ptr> poison, ptr [[X2:%.*]], i64 0
280-
; CHECK-NEXT: [[RET:%.*]] = getelementptr i8, <1 x ptr> [[TMP1]], i64 5
280+
; CHECK-NEXT: [[RET:%.*]] = getelementptr nuw i8, <1 x ptr> [[TMP1]], i64 5
281281
; CHECK-NEXT: ret <1 x ptr> [[RET]]
282282
;
283283
%ins.1 = insertelement <2 x ptr> poison, ptr %x1, i32 0
@@ -290,7 +290,7 @@ define <1 x ptr> @shuffle_gep_nuw(ptr %x1, ptr %x2) {
290290
define <1 x ptr> @shuffle_gep_nusw(ptr %x1, ptr %x2) {
291291
; CHECK-LABEL: @shuffle_gep_nusw(
292292
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <1 x ptr> poison, ptr [[X2:%.*]], i64 0
293-
; CHECK-NEXT: [[RET:%.*]] = getelementptr i8, <1 x ptr> [[TMP1]], i64 5
293+
; CHECK-NEXT: [[RET:%.*]] = getelementptr nusw i8, <1 x ptr> [[TMP1]], i64 5
294294
; CHECK-NEXT: ret <1 x ptr> [[RET]]
295295
;
296296
%ins.1 = insertelement <2 x ptr> poison, ptr %x1, i32 0

0 commit comments

Comments
 (0)