File tree 3 files changed +7
-5
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine
3 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -908,15 +908,16 @@ static bool canSimplifyNullStoreOrGEP(StoreInst &SI) {
908
908
909
909
auto *Ptr = SI.getPointerOperand ();
910
910
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Ptr ))
911
- Ptr = GEPI->getOperand (0 );
911
+ if (GEPI->isInBounds ())
912
+ Ptr = GEPI->getOperand (0 );
912
913
return (isa<ConstantPointerNull>(Ptr ) &&
913
914
!NullPointerIsDefined (SI.getFunction (), SI.getPointerAddressSpace ()));
914
915
}
915
916
916
917
static bool canSimplifyNullLoadOrGEP (LoadInst &LI, Value *Op) {
917
918
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {
918
919
const Value *GEPI0 = GEPI->getOperand (0 );
919
- if (isa<ConstantPointerNull>(GEPI0) &&
920
+ if (isa<ConstantPointerNull>(GEPI0) && GEPI-> isInBounds () &&
920
921
!NullPointerIsDefined (LI.getFunction (), GEPI->getPointerAddressSpace ()))
921
922
return true ;
922
923
}
Original file line number Diff line number Diff line change @@ -69,8 +69,9 @@ define i32 @load_gep_null_inbounds(i64 %X) {
69
69
70
70
define i32 @load_gep_null_not_inbounds (i64 %X ) {
71
71
; CHECK-LABEL: @load_gep_null_not_inbounds(
72
- ; CHECK-NEXT: store i32 undef, i32* null, align 536870912
73
- ; CHECK-NEXT: ret i32 undef
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]]
74
75
;
75
76
%V = getelementptr i32 , i32* null , i64 %X
76
77
%R = load i32 , i32* %V
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ define void @store_at_gep_off_null_inbounds(i64 %offset) {
37
37
define void @store_at_gep_off_null_not_inbounds (i64 %offset ) {
38
38
; CHECK-LABEL: @store_at_gep_off_null_not_inbounds(
39
39
; CHECK-NEXT: [[PTR:%.*]] = getelementptr i32, i32* null, i64 [[OFFSET:%.*]]
40
- ; CHECK-NEXT: store i32 undef , i32* [[PTR]], align 4
40
+ ; CHECK-NEXT: store i32 24 , i32* [[PTR]], align 4
41
41
; CHECK-NEXT: ret void
42
42
;
43
43
%ptr = getelementptr i32 , i32 *null , i64 %offset
You can’t perform that action at this time.
0 commit comments