[PATCH] D68495: [PATCH 07/26] [noalias] EarlyCSE: learn about noalias intrinsics

Jeroen Dobbelaere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 03:16:52 PDT 2020


jeroen.dobbelaere updated this revision to Diff 277738.
jeroen.dobbelaere added a comment.

Rebased to c06b7e2ab5167ad031745a706204abed1aefd823 <https://reviews.llvm.org/rGc06b7e2ab5167ad031745a706204abed1aefd823> (July 14, 2020)


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

https://reviews.llvm.org/D68495

Files:
  llvm/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/test/Transforms/EarlyCSE/basic.ll


Index: llvm/test/Transforms/EarlyCSE/basic.ll
===================================================================
--- llvm/test/Transforms/EarlyCSE/basic.ll
+++ llvm/test/Transforms/EarlyCSE/basic.ll
@@ -54,6 +54,26 @@
   ; CHECK: ret i32 0
 }
 
+; CHECK-LABEL: @test2b(
+define i32 @test2b(i32 *%P, i1 %b) {
+  %V1 = load i32, i32* %P
+  call i8* @llvm.noalias.p0i8.p0i8.p0p0i8.i32(i8* undef, i8* null, i8** null, i32 0, metadata !1)
+  %V2 = load i32, i32* %P
+  %Diff = sub i32 %V1, %V2
+  ret i32 %Diff
+  ; CHECK: ret i32 0
+}
+
+; CHECK-LABEL: @test2c(
+define i32 @test2c(i32 *%P, i1 %b) {
+  %V1 = load i32, i32* %P
+  call i8* @llvm.provenance.noalias.p0i8.p0i8.p0p0i8.p0p0i8.i32(i8* undef, i8* null, i8** null, i8** null, i32 0, metadata !1)
+  %V2 = load i32, i32* %P
+  %Diff = sub i32 %V1, %V2
+  ret i32 %Diff
+  ; CHECK: ret i32 0
+}
+
 ;; Cross block load value numbering.
 ; CHECK-LABEL: @test3(
 define i32 @test3(i32 *%P, i1 %Cond) {
@@ -134,6 +154,24 @@
   ; CHECK: ret i32 42
 }
 
+; CHECK-LABEL: @test6b(
+define i32 @test6b(i32 *%P, i1 %b) {
+  store i32 42, i32* %P
+  call i8* @llvm.noalias.p0i8.p0i8.p0p0i8.i32(i8* undef, i8* null, i8** null, i32 0, metadata !1)
+  %V1 = load i32, i32* %P
+  ret i32 %V1
+  ; CHECK: ret i32 42
+}
+
+; CHECK-LABEL: @test6c(
+define i32 @test6c(i32 *%P, i1 %b) {
+  store i32 42, i32* %P
+  call i8* @llvm.provenance.noalias.p0i8.p0i8.p0p0i8.p0p0i8.i32(i8* undef, i8* null, i8** null, i8** null, i32 0, metadata !1)
+  %V1 = load i32, i32* %P
+  ret i32 %V1
+  ; CHECK: ret i32 42
+}
+
 ;; Trivial dead store elimination.
 ; CHECK-LABEL: @test7(
 define void @test7(i32 *%P) {
@@ -302,3 +340,9 @@
   %and = and i1 %b, %c
   ret i1 %and
 }
+
+declare i8*  @llvm.noalias.p0i8.p0i8.p0p0i8.i32(i8*, i8*, i8**, i32, metadata ) nounwind
+declare i8*  @llvm.provenance.noalias.p0i8.p0i8.p0p0i8.p0p0i8.i32(i8*, i8*, i8**, i8**, i32, metadata ) nounwind
+
+!0 = !{!0, !"some domain"}
+!1 = !{!1, !0, !"some scope"}
Index: llvm/lib/Transforms/Scalar/EarlyCSE.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -986,7 +986,17 @@
                           << '\n');
         AvailableValues.insert(CondI, ConstantInt::getTrue(BB->getContext()));
       } else
-        LLVM_DEBUG(dbgs() << "EarlyCSE skipping assumption: " << Inst << '\n');
+        LLVM_DEBUG(dbgs() << "EarlyCSE skipping intrinsic: " << Inst << '\n');
+      continue;
+    }
+
+    // Likewise, noalias intrinsics don't actually write.
+    if (match(&Inst, m_Intrinsic<Intrinsic::noalias>()) ||
+        match(&Inst, m_Intrinsic<Intrinsic::noalias_decl>()) ||
+        match(&Inst, m_Intrinsic<Intrinsic::provenance_noalias>()) ||
+        match(&Inst, m_Intrinsic<Intrinsic::noalias_arg_guard>())) {
+      LLVM_DEBUG(dbgs() << "EarlyCSE skipping noalias intrinsic: " << Inst
+                        << '\n');
       continue;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68495.277738.patch
Type: text/x-patch
Size: 2969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200714/e0a33460/attachment.bin>


More information about the llvm-commits mailing list