Skip to content

arithmetic miscompile from AArch64 backend #96366

Closed
@regehr

Description

@regehr

this function:

declare void @mumble(i32)

define i32 @f(i32 %0) {
  %2 = sub nuw i32 0, %0
  call void @mumble(i32 %2)
  %3 = sub i32 1, %0
  %4 = sub i32 3, %0
  %5 = mul i32 %0, 1
  %6 = add i32 %3, %5
  %7 = add i32 %6, %4
  ret i32 %7
}

is getting lowered to always return 4:

_f:                       
	stp	x29, x30, [sp, #-16]!       
	mov	w0, wzr
	bl	_mumble
	mov	w0, #4             
	ldp	x29, x30, [sp], #16        
	ret

but that's not right. for example, f(9) should give -5

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions