Skip to content

Commit ef2f843

Browse files
committedDec 24, 2020
Revert "[InstCombine] Check inbounds in load/store of gep null transform (PR48577)"
This reverts commit 899faa5. Upon further consideration, this does not fix the right issue. Doing this fold for non-inbounds GEPs is legal, because the resulting pointer is still based-on null, which has no associated address range, and as such and access to it is UB. https://bugs.llvm.org/show_bug.cgi?id=48577#c3
1 parent e075123 commit ef2f843

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -908,16 +908,15 @@ static bool canSimplifyNullStoreOrGEP(StoreInst &SI) {
908908

909909
auto *Ptr = SI.getPointerOperand();
910910
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Ptr))
911-
if (GEPI->isInBounds())
912-
Ptr = GEPI->getOperand(0);
911+
Ptr = GEPI->getOperand(0);
913912
return (isa<ConstantPointerNull>(Ptr) &&
914913
!NullPointerIsDefined(SI.getFunction(), SI.getPointerAddressSpace()));
915914
}
916915

917916
static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op) {
918917
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {
919918
const Value *GEPI0 = GEPI->getOperand(0);
920-
if (isa<ConstantPointerNull>(GEPI0) && GEPI->isInBounds() &&
919+
if (isa<ConstantPointerNull>(GEPI0) &&
921920
!NullPointerIsDefined(LI.getFunction(), GEPI->getPointerAddressSpace()))
922921
return true;
923922
}

‎llvm/test/Transforms/InstCombine/load.ll

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ define i32 @load_gep_null_inbounds(i64 %X) {
6969

7070
define i32 @load_gep_null_not_inbounds(i64 %X) {
7171
; CHECK-LABEL: @load_gep_null_not_inbounds(
72-
; CHECK-NEXT: [[V:%.*]] = getelementptr i32, i32* null, i64 [[X:%.*]]
73-
; CHECK-NEXT: [[R:%.*]] = load i32, i32* [[V]], align 4
74-
; CHECK-NEXT: ret i32 [[R]]
72+
; CHECK-NEXT: store i32 undef, i32* null, align 536870912
73+
; CHECK-NEXT: ret i32 undef
7574
;
7675
%V = getelementptr i32, i32* null, i64 %X
7776
%R = load i32, i32* %V

‎llvm/test/Transforms/InstCombine/store.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ define void @store_at_gep_off_null_inbounds(i64 %offset) {
3737
define void @store_at_gep_off_null_not_inbounds(i64 %offset) {
3838
; CHECK-LABEL: @store_at_gep_off_null_not_inbounds(
3939
; CHECK-NEXT: [[PTR:%.*]] = getelementptr i32, i32* null, i64 [[OFFSET:%.*]]
40-
; CHECK-NEXT: store i32 24, i32* [[PTR]], align 4
40+
; CHECK-NEXT: store i32 undef, i32* [[PTR]], align 4
4141
; CHECK-NEXT: ret void
4242
;
4343
%ptr = getelementptr i32, i32 *null, i64 %offset

0 commit comments

Comments
 (0)