Skip to content

likely arm64 miscompile due to global isel #55129

@regehr

Description

@regehr

this function:

define i64 @lsr_zext_i1_i64(i1 %b) {
  %1 = zext i1 %b to i64
  %2 = lshr i64 %1, 1
  ret i64 %2
}

gets turned into this arm64 by global isel, using top of tree:

regehr@john-home:~/arm-tests/error_39$ ~/llvm-project/for-alive/bin/llc test-0101865.bc -o - --march=arm64 -global-isel
	.text
	.file	"fast-isel-shift.ll"
	.globl	lsr_zext_i1_i64                 // -- Begin function lsr_zext_i1_i64
	.p2align	2
	.type	lsr_zext_i1_i64,@function
lsr_zext_i1_i64:                        // @lsr_zext_i1_i64
	.cfi_startproc
// %bb.0:
                                        // kill: def $w0 killed $w0 def $x0
	lsl	x0, x0, #63
	ret
.Lfunc_end0:
	.size	lsr_zext_i1_i64, .Lfunc_end0-lsr_zext_i1_i64
	.cfi_endproc
                                        // -- End function
	.section	".note.GNU-stack","",@progbits
regehr@john-home:~/arm-tests/error_39$ 

when %b == 1, it seems clear that the LLVM code should return zero. on the other hand, the arm64 code ends up returning 0x8000000000000000

cc @nunoplopes @nbushehri @ryan-berger @ornata

Metadata

Metadata

Assignees

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