[llvm] 92ef545 - [IPSCCP] Remove noundef when zapping return values
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 05:38:39 PST 2023
Author: Nikita Popov
Date: 2023-02-21T14:38:30+01:00
New Revision: 92ef545b8da2af5ae2e2894d1efd61a49d4b20f9
URL: https://github.com/llvm/llvm-project/commit/92ef545b8da2af5ae2e2894d1efd61a49d4b20f9
DIFF: https://github.com/llvm/llvm-project/commit/92ef545b8da2af5ae2e2894d1efd61a49d4b20f9.diff
LOG: [IPSCCP] Remove noundef when zapping return values
When replacing return values with undef, we should also drop the
noundef attribute (and other UB implying attributes).
Differential Revision: https://reviews.llvm.org/D144461
Added:
Modified:
llvm/lib/Transforms/IPO/SCCP.cpp
llvm/test/Transforms/SCCP/ipsccp-noundef.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp
index 8d19bf6e003fd..c736c298c7dae 100644
--- a/llvm/lib/Transforms/IPO/SCCP.cpp
+++ b/llvm/lib/Transforms/IPO/SCCP.cpp
@@ -338,9 +338,14 @@ static bool runIPSCCP(
// Remove the returned attribute for zapped functions and the
// corresponding call sites.
+ // Also remove any attributes that convert an undef return value into
+ // immediate undefined behavior
+ AttributeMask UBImplyingAttributes =
+ AttributeFuncs::getUBImplyingAttributes();
for (Function *F : FuncZappedReturn) {
for (Argument &A : F->args())
F->removeParamAttr(A.getArgNo(), Attribute::Returned);
+ F->removeRetAttrs(UBImplyingAttributes);
for (Use &U : F->uses()) {
CallBase *CB = dyn_cast<CallBase>(U.getUser());
if (!CB) {
@@ -354,6 +359,7 @@ static bool runIPSCCP(
for (Use &Arg : CB->args())
CB->removeParamAttr(CB->getArgOperandNo(&Arg), Attribute::Returned);
+ CB->removeRetAttrs(UBImplyingAttributes);
}
}
diff --git a/llvm/test/Transforms/SCCP/ipsccp-noundef.ll b/llvm/test/Transforms/SCCP/ipsccp-noundef.ll
index e799f1e02c254..a79ef83162d19 100644
--- a/llvm/test/Transforms/SCCP/ipsccp-noundef.ll
+++ b/llvm/test/Transforms/SCCP/ipsccp-noundef.ll
@@ -2,26 +2,27 @@
@g = external global i8
define internal noundef i32 @ret_noundef() {
-; CHECK-LABEL: define internal noundef i32 @ret_noundef() {
+; CHECK-LABEL: define internal i32 @ret_noundef() {
; CHECK-NEXT: ret i32 undef
;
ret i32 0
}
define internal dereferenceable(1) ptr @ret_dereferenceable() {
-; CHECK-LABEL: define internal dereferenceable(1) ptr @ret_dereferenceable() {
+; CHECK-LABEL: define internal ptr @ret_dereferenceable() {
; CHECK-NEXT: ret ptr undef
;
ret ptr @g
}
define internal dereferenceable_or_null(1) ptr @ret_dereferenceable_or_null() {
-; CHECK-LABEL: define internal dereferenceable_or_null(1) ptr @ret_dereferenceable_or_null() {
+; CHECK-LABEL: define internal ptr @ret_dereferenceable_or_null() {
; CHECK-NEXT: ret ptr undef
;
ret ptr @g
}
+; Non-null is fine, because it does not cause immediate UB.
define internal nonnull ptr @ret_nonnull() {
; CHECK-LABEL: define internal nonnull ptr @ret_nonnull() {
; CHECK-NEXT: ret ptr undef
@@ -29,8 +30,8 @@ define internal nonnull ptr @ret_nonnull() {
ret ptr @g
}
-define internal nonnull noundef ptr @ret_nonnull_noundef() {
-; CHECK-LABEL: define internal noundef nonnull ptr @ret_nonnull_noundef() {
+define internal nonnull ptr @ret_nonnull_noundef() {
+; CHECK-LABEL: define internal nonnull ptr @ret_nonnull_noundef() {
; CHECK-NEXT: ret ptr undef
;
ret ptr @g
@@ -38,11 +39,11 @@ define internal nonnull noundef ptr @ret_nonnull_noundef() {
define void @test() {
; CHECK-LABEL: define void @test() {
-; CHECK-NEXT: [[TMP1:%.*]] = call noundef i32 @ret_noundef()
-; CHECK-NEXT: [[TMP2:%.*]] = call dereferenceable(1) ptr @ret_dereferenceable()
-; CHECK-NEXT: [[TMP3:%.*]] = call dereferenceable_or_null(1) ptr @ret_dereferenceable_or_null()
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @ret_noundef()
+; CHECK-NEXT: [[TMP2:%.*]] = call ptr @ret_dereferenceable()
+; CHECK-NEXT: [[TMP3:%.*]] = call ptr @ret_dereferenceable_or_null()
; CHECK-NEXT: [[TMP4:%.*]] = call nonnull ptr @ret_nonnull()
-; CHECK-NEXT: [[TMP5:%.*]] = call noundef nonnull ptr @ret_nonnull_noundef()
+; CHECK-NEXT: [[TMP5:%.*]] = call nonnull ptr @ret_nonnull_noundef()
; CHECK-NEXT: ret void
;
call noundef i32 @ret_noundef()
More information about the llvm-commits
mailing list