[llvm] c6e54c7 - Revert "[SimplifyCFG] Improve the precision of `PtrValueMayBeModified`"
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 19 15:42:35 PDT 2023
Author: DianQK
Date: 2023-03-20T06:42:07+08:00
New Revision: c6e54c7fec6e612ef4631ef80abca6dcb16adea6
URL: https://github.com/llvm/llvm-project/commit/c6e54c7fec6e612ef4631ef80abca6dcb16adea6
DIFF: https://github.com/llvm/llvm-project/commit/c6e54c7fec6e612ef4631ef80abca6dcb16adea6.diff
LOG: Revert "[SimplifyCFG] Improve the precision of `PtrValueMayBeModified`"
This reverts commit f890f010f6a70addbd885acd0c8d1b9578b6246f.
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
llvm/test/Transforms/SimplifyCFG/unreachable-eliminate-on-ret.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 28a09e820d6ca..9824cb3fb6ade 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7110,16 +7110,7 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
// Look through GEPs. A load from a GEP derived from NULL is still undefined
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Use))
if (GEP->getPointerOperand() == I) {
- // The current base address is null, there are four cases to consider:
- // getelementptr (TY, null, 0) -> null
- // getelementptr (TY, null, not zero) -> may be modified
- // getelementptr inbounds (TY, null, 0) -> null
- // getelementptr inbounds (TY, null, not zero) -> poison iff null is
- // undefined?
- if (!GEP->hasAllZeroIndices() &&
- (!GEP->isInBounds() ||
- NullPointerIsDefined(GEP->getFunction(),
- GEP->getPointerAddressSpace())))
+ if (!GEP->isInBounds() || !GEP->hasAllZeroIndices())
PtrValueMayBeModified = true;
return passingValueIsAlwaysUndefined(V, GEP, PtrValueMayBeModified);
}
diff --git a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
index 1dee0704b3c30..7fe32dfc244d7 100644
--- a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
+++ b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
@@ -444,28 +444,6 @@ else:
define void @test9_gep_inbounds_nonzero(i1 %X, ptr %Y) {
; CHECK-LABEL: @test9_gep_inbounds_nonzero(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
-; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[Y:%.*]], i64 12
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_noundef_arg(ptr [[GEP]])
-; CHECK-NEXT: ret void
-;
-entry:
- br i1 %X, label %if, label %else
-
-if:
- br label %else
-
-else:
- %phi = phi ptr [ %Y, %entry ], [ null, %if ]
- %gep = getelementptr inbounds i8, ptr %phi, i64 12
- call ptr @fn_nonnull_noundef_arg(ptr %gep)
- ret void
-}
-
-define void @test9_gep_inbounds_nonzero_null_defined(i1 %X, ptr %Y) #0 {
-; CHECK-LABEL: @test9_gep_inbounds_nonzero_null_defined(
-; CHECK-NEXT: entry:
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y:%.*]]
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[SPEC_SELECT]], i64 12
; CHECK-NEXT: [[TMP0:%.*]] = call ptr @fn_nonnull_noundef_arg(ptr [[GEP]])
@@ -484,30 +462,9 @@ else:
ret void
}
-define void @test9_gep_inbounds_unknown_null(i1 %X, ptr %Y, i64 %I) {
-; CHECK-LABEL: @test9_gep_inbounds_unknown_null(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
-; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[Y:%.*]], i64 [[I:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_noundef_arg(ptr [[GEP]])
-; CHECK-NEXT: ret void
-;
-entry:
- br i1 %X, label %if, label %else
-
-if:
- br label %else
-
-else:
- %phi = phi ptr [ %Y, %entry ], [ null, %if ]
- %gep = getelementptr inbounds i8, ptr %phi, i64 %I
- call ptr @fn_nonnull_noundef_arg(ptr %gep)
- ret void
-}
-define void @test9_gep_inbounds_unknown_null_defined(i1 %X, ptr %Y, i64 %I) #0 {
-; CHECK-LABEL: @test9_gep_inbounds_unknown_null_defined(
+define void @test9_gep_inbouds_unknown_null(i1 %X, ptr %Y, i64 %I) {
+; CHECK-LABEL: @test9_gep_inbouds_unknown_null(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y:%.*]]
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[SPEC_SELECT]], i64 [[I:%.*]]
@@ -527,27 +484,6 @@ else:
ret void
}
-define void @test9_gep_inbounds_unknown_null_call_noundef(i1 %X, ptr %Y, i64 %I) {
-; CHECK-LABEL: @test9_gep_inbounds_unknown_null_call_noundef(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y:%.*]]
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[SPEC_SELECT]], i64 [[I:%.*]]
-; CHECK-NEXT: [[TMP0:%.*]] = call ptr @fn_noundef_arg(ptr [[GEP]])
-; CHECK-NEXT: ret void
-;
-entry:
- br i1 %X, label %if, label %else
-
-if:
- br label %else
-
-else:
- %phi = phi ptr [ %Y, %entry ], [ null, %if ]
- %gep = getelementptr inbounds i8, ptr %phi, i64 %I
- call ptr @fn_noundef_arg(ptr %gep)
- ret void
-}
-
define void @test9_gep_unknown_null(i1 %X, ptr %Y, i64 %I) {
; CHECK-LABEL: @test9_gep_unknown_null(
; CHECK-NEXT: entry:
diff --git a/llvm/test/Transforms/SimplifyCFG/unreachable-eliminate-on-ret.ll b/llvm/test/Transforms/SimplifyCFG/unreachable-eliminate-on-ret.ll
index 924f98a46ab54..e250a5d02c563 100644
--- a/llvm/test/Transforms/SimplifyCFG/unreachable-eliminate-on-ret.ll
+++ b/llvm/test/Transforms/SimplifyCFG/unreachable-eliminate-on-ret.ll
@@ -55,26 +55,7 @@ define nonnull noundef ptr @test_ret_ptr_nonnull_noundef_gep_nonzero(i1 %cond, p
; CHECK-LABEL: @test_ret_ptr_nonnull_noundef_gep_nonzero(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[COND:%.*]], ptr [[X:%.*]], ptr null
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr ptr, ptr [[SPEC_SELECT]], i64 12
-; CHECK-NEXT: ret ptr [[GEP]]
-;
-entry:
- br i1 %cond, label %bb1, label %bb2
-
-bb1:
- br label %bb2
-
-bb2:
- %phi = phi ptr [ null, %entry ], [ %x, %bb1 ]
- %gep = getelementptr ptr, ptr %phi, i64 12
- ret ptr %gep
-}
-
-define nonnull noundef ptr @test_ret_ptr_nonnull_noundef_gep_inbounds_nonzero(i1 %cond, ptr %x) {
-; CHECK-LABEL: @test_ret_ptr_nonnull_noundef_gep_inbounds_nonzero(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: call void @llvm.assume(i1 [[COND:%.*]])
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds ptr, ptr [[X:%.*]], i64 12
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds ptr, ptr [[SPEC_SELECT]], i64 12
; CHECK-NEXT: ret ptr [[GEP]]
;
entry:
More information about the llvm-commits
mailing list