<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61882>61882</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[PowerPC] Missing sign extension in expansion of sub-word atomic max
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Amanieu
</td>
</tr>
</table>
<pre>
## IR
```llvm
define void @foo(ptr %a, i32 %x) {
%val = trunc i32 %x to i8
%1 = atomicrmw max ptr %a, i8 %val seq_cst
ret void
}
```
## Asm (`-march=ppc32`)
```asm
foo: # @foo
rlwinm 5, 3, 3, 27, 28
li 6, 255
xori 5, 5, 24
slw 7, 4, 5
slw 6, 6, 5
rlwinm 3, 3, 0, 0, 29
and 7, 7, 6
sync
.LBB0_1: # =>This Inner Loop Header: Depth=1
lwarx 8, 0, 3
and 9, 8, 6
srw 9, 9, 5
extsb 9, 9
cmpw 9, 4 # <== Register 4 used here without being sign-extended
bgt 0, .LBB0_3
andc 8, 8, 6
or 8, 7, 8
stwcx. 8, 0, 3
bne 0, .LBB0_1
.LBB0_3:
lwsync
blr
```
## The problem
The second parameter of the function (`%x`, register 4) needs to be sign-extended before being compared against the value extracted from the loaded word.
Downstream bug: https://github.com/rust-lang/rust/issues/100650
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVcGOozgQ_RrnUkrk2EDIgUN3s9GONCuNRnMfGSjAK7BZ2zSZv1_ZJunQ3bsTRbapKpffe4ULYa3sFGJB0meSljsxu16b4mkUSuK8q3TzqyCME8bhy3dCS0Kf1jGj8T8Mr2M0NdhKhfCqZQMkoa3WhOWTM0BYKgh7AcmZX18JOwM5Pcdd4E2vYgDCS3BmVvU9DpwGmT-EHUOQcHqUtRkXGMUVNgfkt2QW__lZW3fba9AFXCv2U_mOxIZZpPtkRyAsJxndj8LUPeHlNNWc-Wh2_lQKYVclPHX-BD7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