Skip to content

[AArch64] Infinite loop when lowering ISD::CLMULR and ISD::CLMULH patterns #182270

@RKSimon

Description

@RKSimon
define <16 x i8> @clmulr_v16i8(<16 x i8> %a, <16 x i8> %b) {
  %a.ext = zext <16 x i8> %a to <16 x i16>
  %b.ext = zext <16 x i8> %b to <16 x i16>
  %clmul = call <16 x i16> @llvm.clmul.v16i16(<16 x i16> %a.ext, <16 x i16> %b.ext)
  %res.ext = lshr <16 x i16> %clmul, splat (i16 7)
  %res = trunc <16 x i16> %res.ext to <16 x i8>
  ret <16 x i8> %res
}

https://rust.godbolt.org/z/49qjzGfM6

It looks to be infinitely folding bitreverse(clmul(bitreverse(x),bitreverse(y))) <->clmulr(x,y)

Most likely a legal operation check is missing

Related to #182039

clmulh has a similar issue:

define <16 x i8> @clmulh_v16i8(<16 x i8> %a, <16 x i8> %b) nounwind {
  %a.ext = zext <16 x i8> %a to <16 x i16>
  %b.ext = zext <16 x i8> %b to <16 x i16>
  %clmul = call <16 x i16> @llvm.clmul.v16i16(<16 x i16> %a.ext, <16 x i16> %b.ext)
  %res.ext = lshr <16 x i16> %clmul, splat (i16 8)
  %res = trunc <16 x i16> %res.ext to <16 x i8>
  ret <16 x i8> %res
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions