[llvm] e360ee6 - [Attributor][FIX] Make AAValueSimplifyArgument aware of thread-dependent constants

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 22:33:21 PDT 2019


Author: Johannes Doerfert
Date: 2019-11-02T00:32:39-05:00
New Revision: e360ee62650609112b08e4ab2249e1e5a8c9e0d0

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

LOG: [Attributor][FIX] Make AAValueSimplifyArgument aware of thread-dependent constants

As in IPConstantProp, thread-dependent constants need not be propagated
over callbacks. Took the comment and test from there, see also D56447.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/test/Transforms/IPConstantProp/thread_local_acs.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 3d6a2c6f94f6..4c8bb0f51e96 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -3653,9 +3653,19 @@ struct AAValueSimplifyArgument final : AAValueSimplifyImpl {
     auto PredForCallSite = [&](AbstractCallSite ACS) {
       // Check if we have an associated argument or not (which can happen for
       // callback calls).
-      if (Value *ArgOp = ACS.getCallArgOperand(getArgNo()))
-        return checkAndUpdate(A, *this, *ArgOp, SimplifiedAssociatedValue);
-      return false;
+      Value *ArgOp = ACS.getCallArgOperand(getArgNo());
+      if (!ArgOp)
+       return false;
+      // We can only propagate thread independent values through callbacks.
+      // This is 
diff erent to direct/indirect call sites because for them we
+      // know the thread executing the caller and callee is the same. For
+      // callbacks this is not guaranteed, thus a thread dependent value could
+      // be 
diff erent for the caller and callee, making it invalid to propagate.
+      if (ACS.isCallbackCall())
+        if (auto *C =dyn_cast<Constant>(ArgOp))
+          if (C->isThreadDependent())
+            return false;
+      return checkAndUpdate(A, *this, *ArgOp, SimplifiedAssociatedValue);
     };
 
     if (!A.checkForAllCallSites(PredForCallSite, *this, true))

diff  --git a/llvm/test/Transforms/IPConstantProp/thread_local_acs.ll b/llvm/test/Transforms/IPConstantProp/thread_local_acs.ll
index 0595a5ca7f13..6e10d23c145f 100644
--- a/llvm/test/Transforms/IPConstantProp/thread_local_acs.ll
+++ b/llvm/test/Transforms/IPConstantProp/thread_local_acs.ll
@@ -1,4 +1,5 @@
 ; RUN: opt -ipconstprop -S < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=1 < %s | FileCheck %s
 ;
 ;    #include <threads.h>
 ;    thread_local int gtl = 0;


        


More information about the llvm-commits mailing list