[PATCH] D144461: [IPSCCP] Remove noundef when zapping return values

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 05:38:47 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92ef545b8da2: [IPSCCP] Remove noundef when zapping return values (authored by nikic).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144461/new/

https://reviews.llvm.org/D144461

Files:
  llvm/lib/Transforms/IPO/SCCP.cpp
  llvm/test/Transforms/SCCP/ipsccp-noundef.ll


Index: llvm/test/Transforms/SCCP/ipsccp-noundef.ll
===================================================================
--- llvm/test/Transforms/SCCP/ipsccp-noundef.ll
+++ 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 @@
   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 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()
Index: llvm/lib/Transforms/IPO/SCCP.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SCCP.cpp
+++ llvm/lib/Transforms/IPO/SCCP.cpp
@@ -338,9 +338,14 @@
 
   // 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 @@
 
       for (Use &Arg : CB->args())
         CB->removeParamAttr(CB->getArgOperandNo(&Arg), Attribute::Returned);
+      CB->removeRetAttrs(UBImplyingAttributes);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144461.499127.patch
Type: text/x-patch
Size: 3380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/d09ad820/attachment.bin>


More information about the llvm-commits mailing list