[llvm] 2c3784c - [SCEV] recognize llvm.annotation intrinsic

Chen Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 3 18:22:00 PDT 2022


Author: Chen Zheng
Date: 2022-07-03T21:02:50-04:00
New Revision: 2c3784cff8595ccf183422ab1875229e4638a57c

URL: https://github.com/llvm/llvm-project/commit/2c3784cff8595ccf183422ab1875229e4638a57c
DIFF: https://github.com/llvm/llvm-project/commit/2c3784cff8595ccf183422ab1875229e4638a57c.diff

LOG: [SCEV] recognize llvm.annotation intrinsic

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D127835

Added: 
    

Modified: 
    llvm/docs/LangRef.rst
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Analysis/ScalarEvolution/annotation-intrinsics.ll

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 8b39408103d41..b2073a1807ad2 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -23575,8 +23575,10 @@ Semantics:
 
 This intrinsic allows annotation of a pointer to an integer with arbitrary
 strings. This can be useful for special purpose optimizations that want to look
-for these annotations. These have no other defined use; they are ignored by code
-generation and optimization.
+for these annotations. These have no other defined use; transformations preserve
+annotations on a best-effort basis but are allowed to replace the intrinsic with
+its first argument without breaking semantics and the intrinsic is completely
+dropped during instruction selection.
 
 '``llvm.annotation.*``' Intrinsic
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23611,10 +23613,12 @@ the line number. It returns the value of the first argument.
 Semantics:
 """"""""""
 
-This intrinsic allows annotations to be put on arbitrary expressions
-with arbitrary strings. This can be useful for special purpose
-optimizations that want to look for these annotations. These have no
-other defined use; they are ignored by code generation and optimization.
+This intrinsic allows annotations to be put on arbitrary expressions with
+arbitrary strings. This can be useful for special purpose optimizations that
+want to look for these annotations. These have no other defined use;
+transformations preserve annotations on a best-effort basis but are allowed to
+replace the intrinsic with its first argument without breaking semantics and the
+intrinsic is completely dropped during instruction selection.
 
 '``llvm.codeview.annotation``' Intrinsic
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 207f4df79e451..aa349f9435ce9 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7365,6 +7365,8 @@ ScalarEvolution::getOperandsToCreate(Value *V, SmallVectorImpl<Value *> &Ops) {
         Ops.push_back(II->getArgOperand(1));
         return nullptr;
       case Intrinsic::start_loop_iterations:
+      case Intrinsic::annotation:
+      case Intrinsic::ptr_annotation:
         Ops.push_back(II->getArgOperand(0));
         return nullptr;
       default:
@@ -7816,8 +7818,10 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
         return getAddExpr(ClampedX, Y, SCEV::FlagNUW);
       }
       case Intrinsic::start_loop_iterations:
-        // A start_loop_iterations is just equivalent to the first operand for
-        // SCEV purposes.
+      case Intrinsic::annotation:
+      case Intrinsic::ptr_annotation:
+        // A start_loop_iterations or llvm.annotation or llvm.prt.annotation is
+        // just eqivalent to the first operand for SCEV purposes.
         return getSCEV(II->getArgOperand(0));
       default:
         break;

diff  --git a/llvm/test/Analysis/ScalarEvolution/annotation-intrinsics.ll b/llvm/test/Analysis/ScalarEvolution/annotation-intrinsics.ll
index bd0704c7e5237..bf72e477ba483 100644
--- a/llvm/test/Analysis/ScalarEvolution/annotation-intrinsics.ll
+++ b/llvm/test/Analysis/ScalarEvolution/annotation-intrinsics.ll
@@ -8,7 +8,7 @@ define i64 @annotation(i64 %x) {
 ; CHECK-LABEL: 'annotation'
 ; CHECK-NEXT:  Classifying expressions for: @annotation
 ; CHECK-NEXT:    %1 = tail call i64 @llvm.annotation.i64(i64 %x, i8* null, i8* null, i32 0)
-; CHECK-NEXT:    --> %1 U: full-set S: full-set
+; CHECK-NEXT:    --> %x U: full-set S: full-set
 ; CHECK-NEXT:  Determining loop execution counts for: @annotation
 ;
   %1 = tail call i64 @llvm.annotation.i64(i64 %x, i8* null, i8* null, i32 0)
@@ -19,7 +19,7 @@ define i8* @ptr_annotation(i8* %x) {
 ; CHECK-LABEL: 'ptr_annotation'
 ; CHECK-NEXT:  Classifying expressions for: @ptr_annotation
 ; CHECK-NEXT:    %1 = call i8* @llvm.ptr.annotation.p0i8(i8* %x, i8* null, i8* null, i32 0, i8* null)
-; CHECK-NEXT:    --> %1 U: full-set S: full-set
+; CHECK-NEXT:    --> %x U: full-set S: full-set
 ; CHECK-NEXT:  Determining loop execution counts for: @ptr_annotation
 ;
   %1 = call i8* @llvm.ptr.annotation.p0i8(i8* %x, i8* null, i8* null, i32 0, i8* null)


        


More information about the llvm-commits mailing list