<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63323>63323</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `DeadArgumentEliminationPass` removes `allocsize` attribute
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          arnetheduck
      </td>
    </tr>
</table>

<pre>
    ```llvm
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-apple-darwin10.0"

declare noalias i8* @malloc2(i64) nounwind inaccessiblememonly

define internal noalias i8* @malloc3(i64 %size) noinline nounwind allockind("alloc,uninitialized") allocsize(0) inaccessiblememonly {
  %xx = call i8* @malloc2(i64 %size)
  ret i8* %xx
}
declare void @escape(i8*)

define i8 @test_malloc(i8* %p) {
  %v1 = load i8, i8* %p
  %obj = call i8* @malloc3(i64 16)
  %v2 = load i8, i8* %p
  %sub = sub i8 %v1, %v2
  call void @escape(i8* %obj)
  ret i8 %sub
}
```

```
opt -opt-bisect-limit=-1 -Os test.ll | llvm-dis
```

```llvm
; ModuleID = '<stdin>'
source_filename = "test.ll"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-apple-darwin10.0"

; Function Attrs: nounwind memory(inaccessiblemem: readwrite)
declare noalias ptr @malloc2(i64) local_unnamed_addr #0

; Function Attrs: noinline nounwind allockind("alloc,uninitialized") memory(inaccessiblemem: readwrite)
define internal fastcc noalias ptr @malloc3() unnamed_addr #1 {
  %xx = tail call ptr @malloc2(i64 16)
  ret ptr %xx
}

declare void @escape(ptr) local_unnamed_addr

define i8 @test_malloc(ptr nocapture readnone %p) local_unnamed_addr {
  %obj = tail call fastcc dereferenceable_or_null(16) ptr @malloc3()
  tail call void @escape(ptr %obj)
  ret i8 0
}

attributes #0 = { nounwind memory(inaccessiblemem: readwrite) }
attributes #1 = { noinline nounwind allockind("alloc,uninitialized") memory(inaccessiblemem: readwrite) }
```


I've bisected this to the `DeadArgumentEliminationPass` - since instcombine is rune after, it misses out on size-based optimizations.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk2P4ygQ_TXkghxhSBznkEO6My3NYbX7DyIMlYQZDBaU09Pz61fgfLnXrenRSntaqRvHpnjUe656WMZojg5gQ5ZPZLmbyR5PPmxkcIAn0L36Pmu8ftuQig1_1p5bwnaEbVGGIyDVEqWVb75HSsSOEs6h6IjYVov7UJiSiG2d_gtT33-WFRHby1AYwYnYXobCjNYfRnOH0dx5fFfyBH4bC8mI2LJhMrJHzJo9BhLOR7wwmM7CldOPutpXi0J2nYVCy_BqXMnm7LZoGDUoKwNQ56U1MlJTE76lZMFaaa1XnPA68eJr6nzvXo3T1DipFMRoGgsttN7ZtzHiwTigxiEEJ-1HyGJApoQvo_kJww7G2bT2tlWO_G6cJpltviX8uXfGGTTSmp-gEyG-HkIHpJqlBxNpUrJ6GpKkad8fP7JWSlr7Ae-H7K7rAuA1OCFcmK92YznP3uiEBlHJLqWUl9xgxkrVKRIh4r69MKxvO3SJyjjtc5nTtl7qnMkzfYi-h_nm24f0ruKX1QOzBM0_BR37Jsela8o-5ZSCM8I1Lu87rcMlvX-oesF-p-mtkR-1e_fQd0gL32HRmAgKC2tag0TsipIWf0aaxJ1bS8nqmSY7KLSJnwG_WwcRT_QPr3sLX3eXDlsR8RxRG0fEl3SX46Lvg4L9wVhwsr014yWB9x37vxM9iC6e6EvvFBrv6BYxRCK2dytILRzeUgWN-zoFBZD6NRi89-l7W-swTJqa9Urafe_Su9J7qXWghAv2mbz-hVf9LpexoR5kR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