Skip to content

ScalarPair product types missing noundef in LLVM return types #157589

@scottmcm

Description

@scottmcm

We do set noundef on scalar return types, but for a pair like (u16, bool) -- which can't have any undef in the LLVM immediate pair type even though it can in memory -- we're currently not:

#[unsafe(no_mangle)]
pub unsafe fn demo_pair(num: u16) -> (u16, bool) {
    unsafe {
        let r = num.unchecked_mul(256);
        (r, num < 256)
    }
}

We just generate https://rust.godbolt.org/z/W154v8xhW

define { i16, i1 } @demo_pair(i16 noundef %num) unnamed_addr {
start:
  %r = mul nuw i16 %num, 256
  %_3 = icmp ult i16 %num, 256
  %0 = insertvalue { i16, i1 } poison, i16 %r, 0
  %1 = insertvalue { i16, i1 } %0, i1 %_3, 1
  ret { i16, i1 } %1
}

It should be

-define { i16, i1 } @demo_pair(i16 noundef %num) unnamed_addr {
+define noundef { i16, i1 } @demo_pair(i16 noundef %num) unnamed_addr {

If it's easier, it looks like we're not setting it for things that don't have undef in memory either (https://rust.godbolt.org/z/rez44Kx58) so could start with that part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions