Skip to content

[PowerPC] Missing sign extension in expansion of sub-word atomic max #61882

Closed
@Amanieu

Description

@Amanieu

IR

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)

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: rust-lang/rust#100650

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions