Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分支中错误定义标量寄存器 #154

Open
wangqinfan opened this issue Dec 4, 2024 · 0 comments
Open

分支中错误定义标量寄存器 #154

wangqinfan opened this issue Dec 4, 2024 · 0 comments
Assignees

Comments

@wangqinfan
Copy link
Collaborator

由CTS的geom_normalize测试发现的问题, 下面是分析出的一个最小复现用例:

unsigned long int __my__mulXf3__(unsigned long int a) {
  unsigned long int Res = a + ((1UL << 52) - 1U);
  int Exp = a + ((1 << 12) >> 1);

  if (Exp <= 6) {
    int shift = 5 - Exp;

    if (shift < 7) {
      Res = Res + shift;
    }

  } else {
    Res &= ((1UL << 52) - 1U);
  }

  return Res;
}

复现的llvm分支: main
复现的编译选项: ./build/bin/clang -O1 -S -target riscv32 -mcpu=ventus-gpgpu test.cl

生成的汇编:

__my__mulXf3__:
	vsub12.vi	v2, v0, 1
	vmsltu.vv	v3, v2, v0
	vadd.vv	v1, v1, v3
	lui	t0, 256
	addi	t0, t0, -1                          # define t0
	vadd12.vi	v3, v0, 2048
	li	t1, 6
	vmv.v.x	v4, t1
	vadd.vx	v1, v1, t0
.Lpcrel_hi0:
	auipc	t1, %pcrel_hi(.LBB0_3)
	setrpc	zero, t1, %pcrel_lo(.Lpcrel_hi0)
	vblt	v4, v3, .LBB0_2
	li	t0, -2043                             # redefine t0
	vmv.v.x	v3, t0
	vsub.vv	v0, v3, v0
	vmsle.vi	v3, v0, 6
	vrsub.vi	v3, v3, 0
	vand.vv	v0, v3, v0
	vsra.vi	v3, v0, 31
	vadd.vv	v0, v2, v0
	vmsltu.vv	v2, v0, v2
	vadd.vv	v1, v1, v3
	vadd.vv	v1, v1, v2
	j	.LBB0_3
.LBB0_2:
	vand.vx	v1, v1, t0                        # use t0
	vadd.vx	v0, v2, zero
	j	.LBB0_3
.LBB0_3:
	join	zero, zero, 0
	ret

分析: 看标的注释, 在分支的前面定义了t0, 在else分支用到了这个t0, 但是在if分支重复定义了t0, 这会导致else分支的t0会被覆盖
现在的初步想法是: 不允许在分支中定义标量寄存器

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants