Skip to content

std::rotl and std::rotr from libcxx 19.1.7 fail for int24_t #30

@ZERICO2005

Description

@ZERICO2005

__int48 appears to be okay? But there are suspicious calls to ld bc, 23 \ call __iand

int i24_rotl(unsigned __x, int __s) noexcept {
  const int __N = 24;
  int __r       = __s % __N;

  if (__r == 0)
    return __x;

  if (__r > 0)
    return (__x << __r) | (__x >> (__N - __r));

  return (__x >> -__r) | (__x << (__N + __r));
}

int i24_rotr(unsigned __x, int __s) noexcept {
  const int __N = 24;
  int __r       = __s % __N;

  if (__r == 0)
    return __x;

  if (__r > 0)
    return (__x >> __r) | (__x << (__N - __r));

  return (__x << -__r) | (__x >> (__N + __r));
}

int main(void) {
    return 0;
}
; ModuleID = 'C:/Users/zerico/Programming/ez80/toolchain/test/standalone/test/obj/lto.bc'
source_filename = "llvm-link"
target datalayout = "e-m:z-p:24:8-p1:16:8-p2:8:8-p3:16:8-p4:24:8-i16:8-i24:8-i32:8-i48:8-i64:8-i96:8-f32:8-f64:8-a:8-n8:16:24-S8"
target triple = "ez80"

; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none)
define dso_local noundef i24 @_Z8i24_rotlji(i24 noundef %0, i24 noundef %1) local_unnamed_addr #0 {
  %3 = srem i24 %1, 24
  %4 = icmp eq i24 %3, 0
  br i1 %4, label %18, label %5

5:                                                ; preds = %2
  %6 = icmp sgt i24 %3, 0
  br i1 %6, label %7, label %12

7:                                                ; preds = %5
  %8 = shl i24 %0, %3
  %9 = sub nuw nsw i24 24, %3
  %10 = lshr i24 %0, %9
  %11 = or i24 %10, %8
  br label %18

12:                                               ; preds = %5
  %13 = sub nsw i24 0, %3
  %14 = lshr i24 %0, %13
  %15 = add nsw i24 %3, 24
  %16 = shl i24 %0, %15
  %17 = or i24 %16, %14
  br label %18

18:                                               ; preds = %12, %7, %2
  %19 = phi i24 [ %11, %7 ], [ %17, %12 ], [ %0, %2 ]
  ret i24 %19
}

; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none)
define dso_local noundef i24 @_Z8i24_rotrji(i24 noundef %0, i24 noundef %1) local_unnamed_addr #0 {
  %3 = srem i24 %1, 24
  %4 = icmp eq i24 %3, 0
  br i1 %4, label %18, label %5

5:                                                ; preds = %2
  %6 = icmp sgt i24 %3, 0
  br i1 %6, label %7, label %12

7:                                                ; preds = %5
  %8 = lshr i24 %0, %3
  %9 = sub nuw nsw i24 24, %3
  %10 = shl i24 %0, %9
  %11 = or i24 %10, %8
  br label %18

12:                                               ; preds = %5
  %13 = sub nsw i24 0, %3
  %14 = shl i24 %0, %13
  %15 = add nsw i24 %3, 24
  %16 = lshr i24 %0, %15
  %17 = or i24 %16, %14
  br label %18

18:                                               ; preds = %12, %7, %2
  %19 = phi i24 [ %11, %7 ], [ %17, %12 ], [ %0, %2 ]
  ret i24 %19
}

; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none)
define dso_local noundef i24 @main() local_unnamed_addr #0 {
  ret i24 0
}

attributes #0 = { minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) "no-trapping-math"="true" "stack-protector-buffer-size"="8" }

!llvm.ident = !{!0}
!llvm.module.flags = !{!1}

!0 = !{!"clang version 17.0.6 (https://github.com/CE-Programming/llvm-project 262d0ad4ac4c788b0e865b638c397598e797c12c)"}
!1 = !{i32 1, !"wchar_size", i32 2}
	.section	.text,"ax",@progbits
	.assume	ADL = 1
	.file	"llvm-link"
	.section	.text.__Z8i24_rotlji,"ax",@progbits
	.globl	__Z8i24_rotlji                  ; -- Begin function _Z8i24_rotlji
	.type	__Z8i24_rotlji,@function
__Z8i24_rotlji:                         ; @_Z8i24_rotlji
; %bb.0:
	ld	hl, -3
	call	__frameset
	ld	iy, (ix + 6)
	ld	hl, (ix + 9)
	ld	bc, 24
	call	__irems
	push	hl
	pop	de
	push	de
	pop	hl
	add	hl, de
	or	a, a
	sbc	hl, de
	jp	z, .LBB0_5
; %bb.1:
	ld	bc, 1
	push	de
	pop	hl
	or	a, a
	sbc	hl, bc
	call	pe, __setflag
	push	de
	pop	hl
	jp	m, .LBB0_3
; %bb.2:
	ld	bc, 23
	call	__iand
	push	hl
	pop	bc
	lea	hl, iy + 0
                                        ; kill: def $c killed $c killed $ubc
	call	__ishl
	ld	(ix - 3), hl
	ex	de, hl
	call	__ineg
	ld	bc, 23
	call	__iand
	push	hl
	pop	bc
	lea	hl, iy + 0
                                        ; kill: def $c killed $c killed $ubc
	call	__ishru
	push	hl
	pop	bc
	ld	hl, (ix - 3)
	jp	.LBB0_4
	.local	.LBB0_3
.LBB0_3:
	call	__ineg
	push	hl
	pop	bc
	lea	hl, iy + 0
                                        ; kill: def $c killed $c killed $ubc
	call	__ishru
	ld	(ix - 3), hl
	ld	hl, 24
                                        ; kill: def $l killed $l killed $uhl
	ld	a, e
	add	a, l
	ld	c, a
	lea	hl, iy + 0
	call	__ishl
	ld	bc, (ix - 3)
	.local	.LBB0_4
.LBB0_4:
	call	__ior
	push	hl
	pop	iy
	.local	.LBB0_5
.LBB0_5:
	lea	hl, iy + 0
	ld	sp, ix
	pop	ix
	ret
	.local	.Lfunc_end0
.Lfunc_end0:
	.size	__Z8i24_rotlji, .Lfunc_end0-__Z8i24_rotlji
                                        ; -- End function
	.section	.text.__Z8i24_rotrji,"ax",@progbits
	.globl	__Z8i24_rotrji                  ; -- Begin function _Z8i24_rotrji
	.type	__Z8i24_rotrji,@function
__Z8i24_rotrji:                         ; @_Z8i24_rotrji
; %bb.0:
	ld	hl, -3
	call	__frameset
	ld	iy, (ix + 6)
	ld	hl, (ix + 9)
	ld	bc, 24
	call	__irems
	push	hl
	pop	de
	push	de
	pop	hl
	add	hl, de
	or	a, a
	sbc	hl, de
	jp	z, .LBB1_5
; %bb.1:
	ld	bc, 1
	push	de
	pop	hl
	or	a, a
	sbc	hl, bc
	call	pe, __setflag
	push	de
	pop	hl
	jp	m, .LBB1_3
; %bb.2:
	ld	bc, 23
	call	__iand
	push	hl
	pop	bc
	lea	hl, iy + 0
                                        ; kill: def $c killed $c killed $ubc
	call	__ishru
	ld	(ix - 3), hl
	ex	de, hl
	call	__ineg
	ld	bc, 23
	call	__iand
	push	hl
	pop	bc
	lea	hl, iy + 0
                                        ; kill: def $c killed $c killed $ubc
	call	__ishl
	push	hl
	pop	bc
	ld	hl, (ix - 3)
	jp	.LBB1_4
	.local	.LBB1_3
.LBB1_3:
	call	__ineg
	push	hl
	pop	bc
	lea	hl, iy + 0
                                        ; kill: def $c killed $c killed $ubc
	call	__ishl
	ld	(ix - 3), hl
	ld	hl, 24
                                        ; kill: def $l killed $l killed $uhl
	ld	a, e
	add	a, l
	ld	c, a
	lea	hl, iy + 0
	call	__ishru
	ld	bc, (ix - 3)
	.local	.LBB1_4
.LBB1_4:
	call	__ior
	push	hl
	pop	iy
	.local	.LBB1_5
.LBB1_5:
	lea	hl, iy + 0
	ld	sp, ix
	pop	ix
	ret
	.local	.Lfunc_end1
.Lfunc_end1:
	.size	__Z8i24_rotrji, .Lfunc_end1-__Z8i24_rotrji
                                        ; -- End function
	.section	.text._main,"ax",@progbits
	.globl	_main                           ; -- Begin function main
	.type	_main,@function
_main:                                  ; @main
; %bb.0:
	or	a, a
	sbc	hl, hl
	ret
	.local	.Lfunc_end2
.Lfunc_end2:
	.size	_main, .Lfunc_end2-_main
                                        ; -- End function
	.ident	"clang version 17.0.6 (https://github.com/CE-Programming/llvm-project 262d0ad4ac4c788b0e865b638c397598e797c12c)"
	.extern	__Unwind_SjLj_Register
	.extern	__Unwind_SjLj_Unregister
	.extern	__ior
	.extern	__irems
	.extern	__frameset
	.extern	__ishl
	.extern	__iand
	.extern	__setflag
	.extern	__ishru
	.extern	__ineg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions