~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
1 year, 9 months ago
Updated
1 year, 9 months ago
Labels
No labels applied.

~sircmpwn 1 year, 9 months ago

Expected 0 here.

~mpu 1 year, 9 months 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 1 year, 9 months ago

~sircmpwn 1 year, 9 months ago

Ah, alright.

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