Skip to content

Commit 6ba5f8c

Browse files
committed
[InstCombine] Fix incorrect inbounds on GEP of GEP (PR44425)
This fixes https://bugs.llvm.org/show_bug.cgi?id=44425. We need to drop inbounds if one of the GEPs is not inbounds. This was already done when creating a new GEP, but not when modifying in place. Differential Revision: https://reviews.llvm.org/D72059
1 parent f9f78cf commit 6ba5f8c

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
19221922

19231923
// Update the GEP in place if possible.
19241924
if (Src->getNumOperands() == 2) {
1925+
GEP.setIsInBounds(GEP.isInBounds() && Src->isInBounds());
19251926
GEP.setOperand(0, Src->getOperand(0));
19261927
GEP.setOperand(1, Sum);
19271928
return &GEP;

llvm/test/Transforms/InstCombine/getelementptr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ define i32* @test_nzgep_zgep([1 x i32]* %base, i64 %idx) {
12011201

12021202
define i32* @test_gep_inbounds_of_gep(i32* %base) {
12031203
; CHECK-LABEL: @test_gep_inbounds_of_gep(
1204-
; CHECK-NEXT: [[PTR2:%.*]] = getelementptr inbounds i32, i32* [[BASE:%.*]], i64 8
1204+
; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i32, i32* [[BASE:%.*]], i64 8
12051205
; CHECK-NEXT: ret i32* [[PTR2]]
12061206
;
12071207
%ptr1 = getelementptr i32, i32* %base, i64 4

llvm/test/Transforms/InstCombine/phi-equal-incoming-pointers.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ define i32 @test_extra_uses_multiple_geps(i1 %cond, i1 %cond2) {
528528
; ALL-NEXT: call void @foo.i32(i32* nonnull [[PTR1_TYPED]])
529529
; ALL-NEXT: br label [[EXIT:%.*]]
530530
; ALL: bb2:
531-
; ALL-NEXT: [[PTR2_1:%.*]] = getelementptr inbounds i8, i8* [[OBJ]], i64 16
531+
; ALL-NEXT: [[PTR2_1:%.*]] = getelementptr i8, i8* [[OBJ]], i64 16
532532
; ALL-NEXT: [[PTR2_TYPED:%.*]] = bitcast i8* [[PTR2_1]] to i32*
533533
; ALL-NEXT: [[RES2:%.*]] = load i32, i32* [[PTR2_TYPED]], align 4
534534
; ALL-NEXT: call void @foo.i32(i32* nonnull [[PTR2_TYPED]])

llvm/test/Transforms/InstCombine/pr26992.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define i1 @test1(i8* %p) personality i32 (...)* @__CxxFrameHandler3 {
99
; CHECK-NEXT: invoke void @may_throw()
1010
; CHECK-NEXT: to label [[INVOKE_CONT:%.*]] unwind label [[CATCH_DISPATCH:%.*]]
1111
; CHECK: invoke.cont:
12-
; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds i8, i8* [[P]], i64 2
12+
; CHECK-NEXT: [[B:%.*]] = getelementptr i8, i8* [[P]], i64 2
1313
; CHECK-NEXT: invoke void @may_throw()
1414
; CHECK-NEXT: to label [[EXIT:%.*]] unwind label [[CATCH_DISPATCH]]
1515
; CHECK: catch.dispatch:

0 commit comments

Comments
 (0)