~mpu/qbe#11: 
shl lowered incorrectly to constant

function l $main() {
@start.0
@body.1
	%.4 =l shl 1, 72
	ret %.4
@.2
	ret
}

Produces:

.globl main
main:
	pushq %rbp
	movq %rsp, %rbp
	movl $256, %eax
	leave
	ret
.type main, @function
.size main, .-main

Ref https://todo.sr.ht/~sircmpwn/hare/753

Status
RESOLVED BY_DESIGN
Submitter
~sircmpwn
Assigned to
No-one
Submitted
2 years ago
Updated
2 years ago
Labels
No labels applied.

~sircmpwn 2 years ago

Expected 0 here.

~mpu 2 years ago

It's documented behavior. "The shifting amount is taken modulo the size of the result type". 72 mod 64 == 8 and 2^8 == 256, so the code behaves according to spec. The constant folder even goes through a bit of sweat to guarantee that: https://c9x.me/git/qbe.git/tree/fold.c#n392

The rationale for this choice is that it's the natural behavior of all qbe targets. So shl in qbe is a simple machine shift left.

~mpu REPORTED BY_DESIGN 2 years ago

~sircmpwn 2 years ago

Ah, alright.

Register here or Log in to comment, or comment via email.