Skip to content

Redundant sext.w in signed overflow checking with -ftrapv #172089

@camel-cdr

Description

@camel-cdr

I noticed a redundant sext.w when enabling -ftrapv: https://godbolt.org/z/4x3end6Gb

int compare(const void* untyped_left, const void* untyped_right) {
  const int* left = untyped_left;
  const int* right = untyped_right;
  return *right - *left;
}

generates:

compare:
        lw      a1, 0(a1)
        lw      a2, 0(a0)
        sub     a0, a1, a2
        subw    a1, a1, a2
        bne     a1, a0, .LBB0_2
        sext.w  a0, a0 # redundant, because a0 == a1
        ret
.LBB0_2:
        unimp

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions