Skip to content

missed optimization for trunc i32 to i16 or i8 when ConstantRange of source already fits in destination #76524

Open
2 of 3 issues completed
@MitalAshok

Description

@MitalAshok

An unnecessary zeroextend / signextend is emitted to zero bits that are already assumed to be zero.

For example:

void take_u16(std::uint16_t);
void u32_to_u16(std::uint32_t x) {
  __builtin_assume(std::in_range<std::uint16_t>(x));
  take_u16(x);
}

Emits an unnecessary movzwl %di, %edi before the tail call. GCC optimizes this to just jump to take_u16.

https://godbolt.org/z/qE77z3a7d

This optimization can also be done on other targets

Sub-issues

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