[clang] 9766fed - [DeadArgElim] Re-apply: Set unused arguments for internal functions

2022-05-12 Thread Quentin Colombet via cfe-commits

Author: Quentin Colombet
Date: 2022-05-12T08:46:16-07:00
New Revision: 9766fed9c10e8ba2f67fad0a3e8b509a8064f7b3

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

LOG: [DeadArgElim] Re-apply: Set unused arguments for internal functions

The re-apply includes fixes to clang tests that were missed in
the original commit.

Original message:
Prior to this patch we would only set to undef the unused arguments of the
external functions. The rationale was that unused arguments of internal
functions wouldn't need to be turned into undef arguments because they
should have been simply eliminated by the time we reach that code.

This is actually not true because there are plenty of cases where we can't
remove unused arguments. For instance, if the internal function is used in
an indirect call, it may not be possible to change the function signature.
Yet, for statically known call-sites we would still like to mark the unused
arguments as undef.

This patch enables the "set undef arguments" optimization on internal
functions when we encounter cases where internal functions cannot be
optimized. I.e., whenever an internal function is marked "live".

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

Added: 
llvm/test/Transforms/DeadArgElim/fct_ptr.ll

Modified: 
clang/test/CodeGen/debug-info-block-vars.c
clang/test/CodeGenObjCXX/nrvo.mm
llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp

Removed: 




diff  --git a/clang/test/CodeGen/debug-info-block-vars.c 
b/clang/test/CodeGen/debug-info-block-vars.c
index dc522a807951..11c899fa3c81 100644
--- a/clang/test/CodeGen/debug-info-block-vars.c
+++ b/clang/test/CodeGen/debug-info-block-vars.c
@@ -11,7 +11,10 @@
 // CHECK: call void @llvm.dbg.declare(metadata i8** %.block_descriptor.addr,
 // CHECK-SAME:metadata !DIExpression())
 // CHECK-OPT-NOT: alloca
-// CHECK-OPT: call void @llvm.dbg.value(metadata i8* %.block_descriptor,
+// Since the block address is not used anywhere in this function,
+// the optimizer (DeadArgElim) has replaced all the false uses
+// (i.e., metadata users) with undef.
+// CHECK-OPT: call void @llvm.dbg.value(metadata i8* undef,
 // CHECK-OPT-SAME:  metadata !DIExpression())
 void f(void) {
   a(^{

diff  --git a/clang/test/CodeGenObjCXX/nrvo.mm 
b/clang/test/CodeGenObjCXX/nrvo.mm
index 89d9ae9639cc..0e4b98996965 100644
--- a/clang/test/CodeGenObjCXX/nrvo.mm
+++ b/clang/test/CodeGenObjCXX/nrvo.mm
@@ -22,7 +22,11 @@ - (X)getNRVO {
 
 X blocksNRVO() {
   return ^{
-// CHECK-LABEL: define internal void @___Z10blocksNRVOv_block_invoke
+// With the optimizer enabled, the DeadArgElim pass is able to
+// mark the block litteral address argument as unused and later the
+// related block_litteral global variable is removed.
+// This allows to promote this call to a fastcc call.
+// CHECK-LABEL: define internal fastcc void @___Z10blocksNRVOv_block_invoke
 X x;
 // CHECK: call void @_ZN1XC1Ev
 // CHECK-NEXT: ret void

diff  --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp 
b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 95f6a4f4fb57..a879a0fb30b3 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -268,9 +268,12 @@ bool 
DeadArgumentEliminationPass::RemoveDeadArgumentsFromCallers(Function &Fn) {
   if (!Fn.hasExactDefinition())
 return false;
 
-  // Functions with local linkage should already have been handled, except the
-  // fragile (variadic) ones which we can improve here.
-  if (Fn.hasLocalLinkage() && !Fn.getFunctionType()->isVarArg())
+  // Functions with local linkage should already have been handled, except if
+  // they are fully alive (e.g., called indirectly) and except for the fragile
+  // (variadic) ones. In these cases, we may still be able to improve their
+  // statically known call sites.
+  if ((Fn.hasLocalLinkage() && !LiveFunctions.count(&Fn)) &&
+  !Fn.getFunctionType()->isVarArg())
 return false;
 
   // Don't touch naked functions. The assembly might be using an argument, or

diff  --git a/llvm/test/Transforms/DeadArgElim/fct_ptr.ll 
b/llvm/test/Transforms/DeadArgElim/fct_ptr.ll
new file mode 100644
index ..2e352666c1f6
--- /dev/null
+++ b/llvm/test/Transforms/DeadArgElim/fct_ptr.ll
@@ -0,0 +1,67 @@
+; RUN: opt -S %s -deadargelim -o - | FileCheck %s
+; In that test @internal_fct is used by an instruction
+; we don't know how to rewrite (the comparison that produces
+; %cmp1).
+; Because of that use, we used to bail out on removing the
+; unused arguments for this function.
+; Yet, we should still be able to rewrite the direct calls that are
+; statically known, by replacing the related arguments w

Re: [PATCH] D12835: [X86][SSE] Replace 128-bit SSE41 PMOVSX intrinsics with native IR

2015-09-15 Thread Quentin Colombet via cfe-commits
qcolombet accepted this revision.
qcolombet added a comment.
This revision is now accepted and ready to land.

LGTM.

Thanks,
-Quentin


Repository:
  rL LLVM

http://reviews.llvm.org/D12835



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r259715 - Revert r259624 - Make CF constant string decl visible to name lookup to fix module errors.

2016-02-03 Thread Quentin Colombet via cfe-commits
Author: qcolombet
Date: Wed Feb  3 16:14:53 2016
New Revision: 259715

URL: http://llvm.org/viewvc/llvm-project?rev=259715&view=rev
Log:
Revert r259624 - Make CF constant string decl visible to name lookup to fix 
module errors.

This breaks some internal bots in stage2: clang seg fault.
Looking with Ben to see what is going on.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/CodeGenObjC/2010-02-01-utf16-with-null.m
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/tentative-cfconstantstring.m
cfe/trunk/test/Modules/Inputs/builtin.h
cfe/trunk/test/Modules/builtins.m

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=259715&r1=259714&r2=259715&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Feb  3 16:14:53 2016
@@ -1385,7 +1385,6 @@ public:
 return QualType();
   }
   void setCFConstantStringType(QualType T);
-  TagDecl *getCFConstantStringDecl() const;
 
   // This setter/getter represents the ObjC type for an NSConstantString.
   void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=259715&r1=259714&r2=259715&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Wed Feb  3 16:14:53 2016
@@ -987,16 +987,13 @@ namespace clang {
 
   /// \brief The internal '__make_integer_seq' template.
   PREDEF_DECL_MAKE_INTEGER_SEQ_ID = 13,
-
-  /// \brief The internal '__NSConstantString' type.
-  PREDEF_DECL_CF_CONSTANT_STRING_ID = 14,
 };
 
 /// \brief The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 15;
+const unsigned int NUM_PREDEF_DECL_IDS = 14;
 
 /// \brief Record code for a list of local redeclarations of a declaration.
 const unsigned int LOCAL_REDECLARATIONS = 50;

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=259715&r1=259714&r2=259715&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb  3 16:14:53 2016
@@ -4868,11 +4868,10 @@ int ASTContext::getIntegerTypeOrder(Qual
   return 1;
 }
 
-TagDecl *ASTContext::getCFConstantStringDecl() const {
+// getCFConstantStringType - Return the type used for constant CFStrings.
+QualType ASTContext::getCFConstantStringType() const {
   if (!CFConstantStringTypeDecl) {
-// This type is designed to be compatible with NSConstantString, but cannot
-// use the same name, since NSConstantString is an interface.
-CFConstantStringTypeDecl = buildImplicitRecord("__NSConstantString");
+CFConstantStringTypeDecl = buildImplicitRecord("NSConstantString");
 CFConstantStringTypeDecl->startDefinition();
 
 QualType FieldTypes[4];
@@ -4902,12 +4901,7 @@ TagDecl *ASTContext::getCFConstantString
 CFConstantStringTypeDecl->completeDefinition();
   }
 
-  return CFConstantStringTypeDecl;
-}
-
-// getCFConstantStringType - Return the type used for constant CFStrings.
-QualType ASTContext::getCFConstantStringType() const {
-  return getTagDeclType(getCFConstantStringDecl());
+  return getTagDeclType(CFConstantStringTypeDecl);
 }
 
 QualType ASTContext::getObjCSuperType() const {

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=259715&r1=259714&r2=259715&view=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Feb  3 16:14:53 2016
@@ -189,10 +189,6 @@ void Sema::Initialize() {
 DeclarationName Protocol = &Context.Idents.get("Protocol");
 if (IdResolver.begin(Protocol) == IdResolver.end())
   PushOnScopeChains(Context.getObjCProtocolDecl(), TUScope);
-
-DeclarationName ConstantString = &Context.Idents.get("NSConstantString");
-if (IdResolver.begin(ConstantString) == IdResolver.end())
-  PushOnScopeChains(Context.getCFConstantStringDecl(), TUScope);
   }
 
   // Initialize Microsoft "predefined C++ types".

M

r259721 - Reapply r259624, it is likely not the commit causing the bot failures.

2016-02-03 Thread Quentin Colombet via cfe-commits
Author: qcolombet
Date: Wed Feb  3 16:41:00 2016
New Revision: 259721

URL: http://llvm.org/viewvc/llvm-project?rev=259721&view=rev
Log:
Reapply r259624, it is likely not the commit causing the bot failures.
Original message:
Make CF constant string decl visible to name lookup to fix module errors

The return type of the __builtin___*StringMakeConstantString functions
is a pointer to a struct, so we need that struct to be visible to name
lookup so that we will correctly merge multiple declarations of that
type if they come from different modules.

Incidentally, to make this visible to name lookup we need to rename the
type to __NSConstantString, since the real NSConstantString is an
Objective-C interface type.  This shouldn't affect anyone outside the
compiler since users of the constant string builtins cast the result
immediately to CFStringRef.

Since this struct type is otherwise implicitly created by the AST
context and cannot access namelookup, we make this a predefined type
and initialize it in Sema.

Note: this issue of builtins that refer to types not visible to name
lookup technically also affects other builtins (e.g. objc_msgSendSuper),
but in all other cases the builtin is a library builtin and the issue
goes away if you include the library that defines the types it uses,
unlike for these constant string builtins.

rdar://problem/24425801

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/CodeGenObjC/2010-02-01-utf16-with-null.m
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/tentative-cfconstantstring.m
cfe/trunk/test/Modules/Inputs/builtin.h
cfe/trunk/test/Modules/builtins.m

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=259721&r1=259720&r2=259721&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Feb  3 16:41:00 2016
@@ -1385,6 +1385,7 @@ public:
 return QualType();
   }
   void setCFConstantStringType(QualType T);
+  TagDecl *getCFConstantStringDecl() const;
 
   // This setter/getter represents the ObjC type for an NSConstantString.
   void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=259721&r1=259720&r2=259721&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Wed Feb  3 16:41:00 2016
@@ -987,13 +987,16 @@ namespace clang {
 
   /// \brief The internal '__make_integer_seq' template.
   PREDEF_DECL_MAKE_INTEGER_SEQ_ID = 13,
+
+  /// \brief The internal '__NSConstantString' type.
+  PREDEF_DECL_CF_CONSTANT_STRING_ID = 14,
 };
 
 /// \brief The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 14;
+const unsigned int NUM_PREDEF_DECL_IDS = 15;
 
 /// \brief Record code for a list of local redeclarations of a declaration.
 const unsigned int LOCAL_REDECLARATIONS = 50;

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=259721&r1=259720&r2=259721&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb  3 16:41:00 2016
@@ -4868,10 +4868,11 @@ int ASTContext::getIntegerTypeOrder(Qual
   return 1;
 }
 
-// getCFConstantStringType - Return the type used for constant CFStrings.
-QualType ASTContext::getCFConstantStringType() const {
+TagDecl *ASTContext::getCFConstantStringDecl() const {
   if (!CFConstantStringTypeDecl) {
-CFConstantStringTypeDecl = buildImplicitRecord("NSConstantString");
+// This type is designed to be compatible with NSConstantString, but cannot
+// use the same name, since NSConstantString is an interface.
+CFConstantStringTypeDecl = buildImplicitRecord("__NSConstantString");
 CFConstantStringTypeDecl->startDefinition();
 
 QualType FieldTypes[4];
@@ -4901,7 +4902,12 @@ QualType ASTContext::getCFConstantString
 CFConstantStringTypeDecl->completeDefinition();
   }
 
-  return getTagDeclType(CFConstantStringTypeDecl);
+  return CFConstantStringTypeDecl;
+}
+
+// getCFConstantStringType - Retur

Re: [PATCH] D17092: [X86] Add -mseparate-stack-seg

2016-03-08 Thread Quentin Colombet via cfe-commits
qcolombet resigned from this revision.
qcolombet edited reviewers, added: craig.topper; removed: qcolombet.
qcolombet added a comment.

Hi Craig,

Could you have a look? I am not confident enough with clang to give more 
feedback than Elena.

Cheers,
-Quentin


http://reviews.llvm.org/D17092



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits