Skip to content

assert! and assert_eq! generate different assembly #55914

Open
@hellow554

Description

@hellow554

Concidering this simple code

pub fn foo1(a: u32, b: u32) -> bool {
    assert!(a == b);
    true
}

pub fn foo2(a: u32, b: u32) -> bool {
    assert_eq!(a, b);
    true
}

The generate very different assembly

example::foo1:
  push rax
  cmp edi, esi
  jne .LBB7_1
  mov al, 1
  pop rcx
  ret
.LBB7_1:
// panicing

example::foo2:
  sub rsp, 104
  mov dword ptr [rsp], edi
  mov dword ptr [rsp + 4], esi
  mov rax, rsp
  mov qword ptr [rsp + 8], rax
  lea rax, [rsp + 4]
  mov qword ptr [rsp + 16], rax
  cmp edi, esi
  jne .LBB8_1
  mov al, 1
  add rsp, 104
  ret
.LBB8_1: 
// panicing

There is a difference regarding the parameter formatting in the "assert_false" branch LBB7_1 and LBB8_1, but what's even worse is, that the assert itself does differ and I don't see a reason why.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions