[PATCH] D124699: [DeadArgElim] Set unused arguments for internal functions

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 19:03:41 PDT 2022


qcolombet added a comment.

Alright, at first I thought it was a latent bug in the dead argument elimination pass and now I think the two failing tests just need updating.
I'll upload a diff with the fix tests. (See below for the diff of the tests themselves.)

Details
=======

I initially thought that we were wrongly optimizing `noundef` arguments. However, I believe that's not the case, because when we replace an argument with `undef`, we know that there is no use of this argument, so no undefined behavior is attached to it. This was clearly taken into account because the pass properly removes all the UB implying attributes (see `Fn.removeParamAttrs(Arg.getArgNo(), UBImplyingAttributes);` later in the method I modified.)

Now, regarding the two clang tests that failed: One is expecting the debug info to contain a reference to an argument that is not used and that the optimized replaced by `undef` and the other is tripping on the fact that we can use fastcc since we proved that the address of the block function is not used.

Here the full diff for fixing the tests.

  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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124699



More information about the llvm-commits mailing list