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

    <tr>
        <th>Summary</th>
        <td>
            optimization oppotunity with option "-mattr=+unaligned-scalar-mem"
        </td>
    </tr>

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

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

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

<pre>
    With the fix for https://github.com/llvm/llvm-project/issues/56110,
For such ll code:
```
$ cat x.ll
; ModuleID = 'x.c'
source_filename = "x.c"
target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
target triple = "riscv32-unknown-unknown-elf"

; Function Attrs: argmemonly mustprogress nofree norecurse nosync nounwind willreturn
define dso_local void @foo_set(ptr nocapture noundef %a, i32 noundef %v) local_unnamed_addr #0 {
entry:
  %bf.load = load i96, ptr %a, align 1
  %0 = and i32 %v, 65535
  %bf.value = zext i32 %0 to i96
  %bf.shl = shl nuw nsw i96 %bf.value, 24
  %bf.clear = and i96 %bf.load, -1099494850561
  %bf.set = or i96 %bf.clear, %bf.shl
  store i96 %bf.set, ptr %a, align 1
  ret void
}

attributes #0 = { argmemonly mustprogress nofree norecurse nosync nounwind willreturn "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true"
"stack-protector-buffer-size"="8" "target-features"="+a,+c,+m,+relax,-save-restore" }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, !"target-abi", !"ilp32"}
!2 = !{i32 1, !"SmallDataLimit", i32 8}
!3 = !{!"clang version 15.0.0 (c2bb2e5973acd24c45c1823e95e8e33003c59484)"}
```
When compile it with -mattr=+unaligned-scalar-mem, such asm code would be generated:

```
foo_set:                                # @foo_set
# %bb.0:                                # %entry
    srli    a2, a1, 8
    sb  a1, 3(a0)
    sb  a2, 4(a0)
    ret
```

But ideally I think such code should be genereated:

```
foo_set:                                # @foo_set
# %bb.0:                                # %entry
    sh  a1, 3(a0)
    ret
```



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVVktv4zYQ_jXyhZAhkZIfBx_iNQIs0AIF9rBHg6JGFhuKFEjKjvPrO6RkR852swXaSw2bpDRPzuMbV6a-7r5L3xLfAmnkK2mMJa33vUvYU0Kf8XtC8lAthenwQanzbUt7a_4E4fFROjeAw0O5yvMsoV-S7JBkT8-oyw2iJUoRYWoIKiMhWWXTd3ykBRHck9elUtMbtie_m3pQ8PVAEoY_un5dClxHujODFXBspALNO5hYaGShI4vn9gSe1Nxzxa9m8DcmSDt0BNIeV0bjkspVgYdVkWp8-JbTzUc13spe3e1Y6cQZOQf9os1F33dQzV3w_SLPgxZeGk2evLchrgR1dtAZra6kG5zHQJ4sOEe0aSwAbhbEYF04uasWuA36InVNLlIpC36welRfQyM1kNqZozKCK3I2siZJkTXGHB1gbja9tygveI9SEDWhEF6i5JgnIhmdvzsndEuipuOgQ2TrI69riySWkWS9H62C9vZ6TyYJglWzVIbXMUDxILeroD9Yv9niSp40yWdSWeTneLHgx2j_C1mVJSsfdZ-5Gsbov8Grv3FnxJto6IHXtSpyhl0PF6LdJTDNNQUrtHgUEwq4fffnLhBuE_jTPNtui22xKTOs8g8mYawurPd3wagwSN7dugk5jwmeccZEfRorzHlM7VRU68O8xjiWlawGD27KUyjS9f6_qLJQ7I3FOkh7I7UHG8qbHXDVRmMYQxpoJ3Wq4MRVekY4MDa9yNq3d85sYtMm9Zb3vdSntOMzBm9DRm5tQ6nzXLwEdPGjumpoGrCpk29wl9lMSsf2TBvgobzdnZ7QfYgjbmLcunGzoPgrHlPHz5CiREhF1PUY04TmAeOWXQShZaP4yU3dn4c-oBHmwlM-7fRdwyQra2yURyH2o5lsxhHq-qYPnbqIltvj7d5TtxZzO_nPhafI8EpOwuNrqXoEPfrgLf25lm8dV-qAGP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