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

    <tr>
        <th>Summary</th>
        <td>
            `@llvm.abs.i64` optimizes differently versus target-specific `@llvm.aarch64.neon.abs.i64`
        </td>
    </tr>

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

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

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

<pre>
    I'm not sure one is really better than the other, but it's the difference that is weird. My reading of https://llvm.org/docs/LangRef.html#llvm-abs-intrinsic is that the second argument being false means that the behavior is in fact wrapping, like the neon instruction.

https://godbolt.org/z/fTvxc4z3z

```llvm
target triple = "aarch64-unknown-linux-gnu"

define noundef i64 @foo(i64 noundef %a) unnamed_addr {
start:
  %_0.sroa.0.0 = tail call i64 @llvm.abs.i64(i64 %a, i1 false)
  ret i64 %_0.sroa.0.0
}

define noundef i64 @bar(i64 noundef %a) unnamed_addr {
start:
  %_0.i = tail call noundef i64 @llvm.aarch64.neon.abs.i64(i64 noundef %a) #3
  ret i64 %_0.i
}

declare i64 @llvm.aarch64.neon.abs.i64(i64) unnamed_addr #1

declare i64 @llvm.abs.i64(i64, i1 immarg) #2
```

At `-O0` they produce the same instructions, but at `-O3` they do not

```asm
foo: // @foo
        cmp     x0, #0
        cneg    x0, x0, mi
 ret
bar:                                    // @bar
        fmov    d0, x0
        abs     d0, d0
        fmov    x0, d0
        ret
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVNGK6zYQ_Rr5ZYiRJTvJPvgh9y6BQkuh9P0iSyNbvbJkJDm72a8vspNNNndZCjUhwp6ZM3PGx0fEaHqH2JLmG2meCzGnwYdWe_sTQ1J4Kjqvzu1vhO1GcD5BnAOCdwgmQkBh7Rk6TAkDpEE4SAOCTwMGwr5DNycwibBdXJ4rozUGdBJzbsoIL2i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