[llvm] 5fac7c6 - [GVN] Propagate llvm.access.group metadata of loads

KAWASHIMA Takahiro via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 31 18:01:43 PDT 2021


Author: KAWASHIMA Takahiro
Date: 2021-04-01T10:00:48+09:00
New Revision: 5fac7c60467c58d567779c3568dcfeb8d164af21

URL: https://github.com/llvm/llvm-project/commit/5fac7c60467c58d567779c3568dcfeb8d164af21
DIFF: https://github.com/llvm/llvm-project/commit/5fac7c60467c58d567779c3568dcfeb8d164af21.diff

LOG: [GVN] Propagate llvm.access.group metadata of loads

Before this change, the `llvm.access.group` metadata was dropped
when moving a load instruction in GVN. This prevents vectorizing
a C/C++ loop with `#pragma clang loop vectorize(assume_safety)`.
This change propagates the metadata as well as other metadata if
it is safe (the move-destination basic block and source basic
block belong to the same loop).

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/GVN.cpp
    llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 65f7d0498adf3..ecfca8076f87a 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1406,6 +1406,10 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock,
       NewLoad->setMetadata(LLVMContext::MD_invariant_group, InvGroupMD);
     if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range))
       NewLoad->setMetadata(LLVMContext::MD_range, RangeMD);
+    if (auto *AccessMD = LI->getMetadata(LLVMContext::MD_access_group))
+      if (this->LI && this->LI->getLoopFor(LI->getParent()) ==
+                          this->LI->getLoopFor(UnavailablePred))
+        NewLoad->setMetadata(LLVMContext::MD_access_group, AccessMD);
 
     // We do not propagate the old load's debug location, because the new
     // load now lives in a 
diff erent BB, and we want to avoid a jumpy line

diff  --git a/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll b/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll
index 5bbbf75955fd5..5cde83c1e21bd 100644
--- a/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll
+++ b/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll
@@ -20,7 +20,7 @@ define dso_local void @test1(i32* nocapture readonly %aa, i32* nocapture %bb) lo
 ; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], 100
 ; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_BODY_FOR_BODY_CRIT_EDGE]], label [[FOR_END:%.*]]
 ; CHECK:       for.body.for.body_crit_edge:
-; CHECK-NEXT:    [[DOTPRE]] = load i32, i32* [[IDX]], align 4
+; CHECK-NEXT:    [[DOTPRE]] = load i32, i32* [[IDX]], align 4, !llvm.access.group !0
 ; CHECK-NEXT:    br label [[FOR_BODY]]
 ; CHECK:       for.end:
 ; CHECK-NEXT:    ret void
@@ -68,7 +68,7 @@ define dso_local void @test2(i32* nocapture readonly %aa, i32* nocapture %bb) lo
 ; CHECK-NEXT:    store i32 [[MUL]], i32* [[AA]], align 4, !llvm.access.group !1
 ; CHECK-NEXT:    br i1 true, label [[FOR_BODY2_FOR_BODY2_CRIT_EDGE]], label [[FOR_END:%.*]]
 ; CHECK:       for.body2.for.body2_crit_edge:
-; CHECK-NEXT:    [[DOTPRE1]] = load i32, i32* [[IDX]], align 4
+; CHECK-NEXT:    [[DOTPRE1]] = load i32, i32* [[IDX]], align 4, !llvm.access.group !1
 ; CHECK-NEXT:    br label [[FOR_BODY2]]
 ; CHECK:       for.end:
 ; CHECK-NEXT:    br i1 false, label [[FOR_END_FOR_BODY_CRIT_EDGE:%.*]], label [[END:%.*]]


        


More information about the llvm-commits mailing list