Skip to content

sext(square nsw) produces unnecessary zext on riscv64/mips64/loongarch64 #62587

Closed
@sorear

Description

@sorear

Minimal C reproducer(s):

int a(int x) { return x*x; }
long b(int x) { return x*x; }

Expected output (on riscv64, generated with -fwrapv):

a:                                      # @a
        mulw    a0, a0, a0
        ret

What is actually generated:

a:                                      # @a
        mulw    a0, a0, a0
        slli    a0, a0, 32
        srli    a0, a0, 32
        ret

compiler explorer link: https://godbolt.org/z/Yq898xoT1. Clang 14 produces the optimal code for a but not for b.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions