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

    <tr>
        <th>Summary</th>
        <td>
            [IROutliner] MultiSource/Benchmarks/MiBench/network-patricia is larger with IR outliner enabled
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            llvm:optimizations,
            llvm:codesize
      </td>
    </tr>

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

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

<pre>
    Compiling for AArch64.

-Oz = 5.86% bigger with outliner
-O2 = 6.78% bigger with outliner

(To be fair this is a tiny benchmark)

This was done by compiling the LLVM test suite using LNT and looking at the `size.__text` results.

# Reproducing

The IR for the worst size-increased file in network-patricia @ -O2 is here: https://godbolt.org/z/KGfEaMafb

Compiling this to assembly and using asm-printer remarks...

```
$ ~/llvm-project/build/bin/clang -S -O2 -Rpass-analysis=asm-printer /tmp/patricia-stripped.ll -o /dev/null
remark: <unknown>:0:0: 128 instructions in function [-Rpass-analysis=asm-printer]

$ ~/llvm-project/build/bin/clang -S -O2 -Rpass-analysis=asm-printer -mllvm -ir-outliner /tmp/patricia-stripped.ll -o /dev/null
remark: <unknown>:0:0: 144 instructions in function [-Rpass-analysis=asm-printer]
remark: <unknown>:0:0: 6 instructions in function [-Rpass-analysis=asm-printer]
remark: <unknown>:0:0: 5 instructions in function [-Rpass-analysis=asm-printer]
```

Baseline: 128 instructions
Outliner: 155 instructions

I think there are a couple issues here, one of them probably reduces down to this: https://godbolt.org/z/Pfq8oK68P

```
$ ~/llvm-project/build/bin/clang -S -O2 -Rpass-analysis=asm-printer /tmp/test.ll -o /dev/null 
remark: <unknown>:0:0: 7 instructions in function [-Rpass-analysis=asm-printer]
remark: <unknown>:0:0: 7 instructions in function [-Rpass-analysis=asm-printer]

$ ~/llvm-project/build/bin/clang -S -O2 -mllvm -ir-outliner -Rpass-analysis=asm-printer /tmp/test.ll -o /dev/null
remark: <unknown>:0:0: 4 instructions in function [-Rpass-analysis=asm-printer]
remark: <unknown>:0:0: 4 instructions in function [-Rpass-analysis=asm-printer]
remark: <unknown>:0:0: 7 instructions in function [-Rpass-analysis=asm-printer]
```

Baseline: 14 instructions total
Outliner: 15 instructions total

# Analysis

Using `llvm-remark-size-diff` on network-patricia at -O2, we can see that the only difference is that main increased by 13 instructions, and two outlined functions were added.

```
++ > outlined_ir_func_0, 5 instrs, 0 stack B
++ > outlined_ir_func_1, 5 instrs, 0 stack B
== > main, 13 instrs, 0 stack B

### Summary ###
Total change: 
 instruction count: 23 (6.78%)
 stack byte usage: None
```

Then I just recompiled with `clang -save-temps` and yoinked out the bitcode.

cc @AndrewLitteken 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFV9ty4jgQ_Rrz0mWXsTGXBx5ISLZSk8xMJdl9pWRLBg2yxEpyWPL1220bBrJskqrJZqtsGUkttfp2dMgN300vTbWRSuollMbCbGaL1XAQBfE8iGdtG357hiCdQxaNh0GSQS6XS2FhK_0KTO1xrbB7yaSRHEaj8euSXZuMHw3kAkomLfiVdIAPAy_1Dod1saqYXQfJ5HjRI4ltmQNutIB8B8XBAr8ScHv7xx144Ty4WnoBtaOZ26-PwDQHZcya-sw3wsEwdvJZRIuFF3957IEVrlbeRafHTOFebKzhdYGLTw8j4Oa-cR3ttzWWFOOWodSFFcwJDqVUAqQGLTzOr8MN81YWkkEwiIFchvashBVBOoOV9xuHP4LkGp-l4blRPjJ2ib1nfL_8Vl6xO1bmx4e4PHIA7uUNMOdElatdY3PrAeaqcGOl9hgQK8ivLopOzRzG3dNZPYBgdIVKlXqiteaHKDx281oqTl-psS0Uw93Dh8aS8H6DqkOmmdo5iYbMj9WitK822O49EDr8bjaCR0pBaEiAiydsda1Ue4r2qOSaIL2s9VqbrQ7SKxyIuxf6yRjdi1vVhZdGO_J1WeumA0F28eqhgmx-GuqPNjqsaCcI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