[llvm] dfc821a - [OpenMPOpt][FIX] Ensure a dependence for KernelEnvC queries

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 23:16:42 PDT 2023


Author: Johannes Doerfert
Date: 2023-08-10T23:16:25-07:00
New Revision: dfc821ae89f11b82013995eda339454ad5104a45

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

LOG: [OpenMPOpt][FIX] Ensure a dependence for KernelEnvC queries

When other AAs query the current value of KernelEnvC via the callback
KernelConfigurationSimplifyCB we need to ensure they are now dependent
on the AAKernelInfo that is in charge of the KernelEnvC.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/IPO/Attributor.h
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/lib/Transforms/IPO/OpenMPOpt.cpp
    llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index b311f7b663524c..5793ca4f9b5359 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -318,8 +318,9 @@ inline bool operator==(const RangeTy &A, const RangeTy &B) {
 inline bool operator!=(const RangeTy &A, const RangeTy &B) { return !(A == B); }
 
 /// Return the initial value of \p Obj with type \p Ty if that is a constant.
-Constant *getInitialValueForObj(Attributor &A, Value &Obj, Type &Ty,
-                                const TargetLibraryInfo *TLI,
+Constant *getInitialValueForObj(Attributor &A,
+                                const AbstractAttribute &QueryingAA, Value &Obj,
+                                Type &Ty, const TargetLibraryInfo *TLI,
                                 const DataLayout &DL,
                                 RangeTy *RangePtr = nullptr);
 

diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 773ae8444d4e9a..a2ab36abb06689 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -226,10 +226,10 @@ bool AA::isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA,
   return InstanceInfoAA && InstanceInfoAA->isAssumedUniqueForAnalysis();
 }
 
-Constant *AA::getInitialValueForObj(Attributor &A, Value &Obj, Type &Ty,
-                                    const TargetLibraryInfo *TLI,
-                                    const DataLayout &DL,
-                                    AA::RangeTy *RangePtr) {
+Constant *
+AA::getInitialValueForObj(Attributor &A, const AbstractAttribute &QueryingAA,
+                          Value &Obj, Type &Ty, const TargetLibraryInfo *TLI,
+                          const DataLayout &DL, AA::RangeTy *RangePtr) {
   if (isa<AllocaInst>(Obj))
     return UndefValue::get(&Ty);
   if (Constant *Init = getInitialValueOfAllocation(&Obj, TLI, &Ty))
@@ -242,7 +242,7 @@ Constant *AA::getInitialValueForObj(Attributor &A, Value &Obj, Type &Ty,
   Constant *Initializer = nullptr;
   if (A.hasGlobalVariableSimplificationCallback(*GV)) {
     auto AssumedGV = A.getAssumedInitializerFromCallBack(
-        *GV, /* const AbstractAttribute *AA */ nullptr, UsedAssumedInformation);
+        *GV, &QueryingAA, UsedAssumedInformation);
     Initializer = *AssumedGV;
     if (!Initializer)
       return nullptr;
@@ -526,8 +526,8 @@ static bool getPotentialCopiesOfMemoryValue(
 
     if (IsLoad && !HasBeenWrittenTo && !Range.isUnassigned()) {
       const DataLayout &DL = A.getDataLayout();
-      Value *InitialValue =
-          AA::getInitialValueForObj(A, Obj, *I.getType(), TLI, DL, &Range);
+      Value *InitialValue = AA::getInitialValueForObj(
+          A, QueryingAA, Obj, *I.getType(), TLI, DL, &Range);
       if (!InitialValue) {
         LLVM_DEBUG(dbgs() << "Could not determine required initial value of "
                              "underlying object, abort!\n");

diff  --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 39b79b9134f8ad..7e9bbdacfc73b4 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -3667,6 +3667,12 @@ struct AAKernelInfoFunction : AAKernelInfo {
         KernelConfigurationSimplifyCB =
             [&](const GlobalVariable &GV, const AbstractAttribute *AA,
                 bool &UsedAssumedInformation) -> std::optional<Constant *> {
+      if (!isAtFixpoint()) {
+        if (!AA)
+          return nullptr;
+        UsedAssumedInformation = true;
+        A.recordDependence(*this, *AA, DepClassTy::OPTIONAL);
+      }
       return KernelEnvC;
     };
 

diff  --git a/llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll b/llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll
index 217c6a83d302fd..2ac0ae5b307e4b 100644
--- a/llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll
+++ b/llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll
@@ -27,17 +27,21 @@ define i32 @fputs() {
 define internal i32 @__kmpc_target_init(ptr %0) {
 ; AMDGPU-LABEL: define {{[^@]+}}@__kmpc_target_init
 ; AMDGPU-SAME: (ptr [[TMP0:%.*]]) #[[ATTR1:[0-9]+]] {
-; AMDGPU-NEXT:    [[TMP2:%.*]] = tail call i32 @llvm.amdgcn.workitem.id.x() #[[ATTR3:[0-9]+]]
-; AMDGPU-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 0
-; AMDGPU-NEXT:    br i1 [[TMP3]], label [[TMP4:%.*]], label [[TMP5:%.*]]
-; AMDGPU:       4:
+; AMDGPU-NEXT:    [[TMP2:%.*]] = load i8, ptr getelementptr (i8, ptr addrspacecast (ptr addrspace(1) @__omp_offloading_10302_b20a40e_main_l4_kernel_environment to ptr), i64 2), align 2
+; AMDGPU-NEXT:    [[TMP3:%.*]] = and i8 [[TMP2]], 2
+; AMDGPU-NEXT:    [[TMP4:%.*]] = icmp ne i8 [[TMP3]], 0
+; AMDGPU-NEXT:    [[TMP5:%.*]] = tail call i32 @llvm.amdgcn.workitem.id.x() #[[ATTR3:[0-9]+]]
+; AMDGPU-NEXT:    [[TMP6:%.*]] = icmp eq i32 [[TMP5]], 0
+; AMDGPU-NEXT:    [[OR_COND:%.*]] = select i1 [[TMP4]], i1 [[TMP6]], i1 false
+; AMDGPU-NEXT:    br i1 [[OR_COND]], label [[TMP7:%.*]], label [[TMP8:%.*]]
+; AMDGPU:       7:
 ; AMDGPU-NEXT:    store i8 0, ptr addrspace(3) null, align 2147483648
-; AMDGPU-NEXT:    br label [[TMP5]]
-; AMDGPU:       5:
-; AMDGPU-NEXT:    br label [[TMP7:%.*]]
-; AMDGPU:       6:
+; AMDGPU-NEXT:    br label [[TMP8]]
+; AMDGPU:       8:
+; AMDGPU-NEXT:    br label [[TMP10:%.*]]
+; AMDGPU:       9:
 ; AMDGPU-NEXT:    unreachable
-; AMDGPU:       7:
+; AMDGPU:       10:
 ; AMDGPU-NEXT:    ret i32 0
 ;
   %2 = getelementptr %struct.ConfigurationEnvironmentTy.8, ptr %0, i64 0, i32 2
@@ -97,10 +101,10 @@ attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memo
 
 ;.
 ; AMDGPU: attributes #[[ATTR0]] = { nounwind }
-; AMDGPU: attributes #[[ATTR1]] = { norecurse nosync nounwind memory(write) }
+; AMDGPU: attributes #[[ATTR1]] = { norecurse nosync nounwind }
 ; AMDGPU: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
 ; AMDGPU: attributes #[[ATTR3]] = { nosync }
-; AMDGPU: attributes #[[ATTR4]] = { nosync nounwind memory(write) }
+; AMDGPU: attributes #[[ATTR4]] = { nosync nounwind }
 ;.
 ; AMDGPU: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 51}
 ;.


        


More information about the llvm-commits mailing list