Open HazyFish opened 1 year ago
@DataCorrupted
@llvm/issue-subscribers-backend-aarch64
Reproduction https://godbolt.org/z/TzvYj99fo
Scope This only happens when sve is included, with srem a constant vector of -1. This happens for upstream and LLVM 15-17.
Cause A direct cause is in AArch64TargetLowering::LowerFixedLengthVectorIntDivideToSVE, Log2_64(SplatVal) created a potential division by zero(log(1) == 0). Similar for AArch64TargetLowering::LowerDIV.
However, this bug won't be triggered on vector of 1s or scalar 1 or -1 for the following reason:
In DAGCombiner::visitSDIVLike, any divide by vector of 1s or scalar 1 or -1 is already lowered. But a vector of -1s failed to get lowered because isConstantOrConstantVector(Inexact) is false. Inexact comes from vxi32 splat 16 - vxi16 splat 0. The weird effect is the bitwidth of element is 16, but the APInt extracted from the elements have bitwidth of 32. With clause Const->getAPIntValue().getBitWidth() != BitWidth, Inexact is not considered a Constant Vector. Why was this clause there when you commit it?
Fixes An immediate fix would be to add a guard at AArch64TargetLowering::LowerFixedLengthVectorIntDivideToSVE to avoid any 1 or -1s. Fixing isConstantOrConstantVector should also be possible, but I need some help on that.
Description
When enabling
sve
feature on AArch64, the following code crashes withLLVM ERROR: Cannot select: t25: nxv16i8 = AArch64ISD::SRAD_MERGE_OP1 t24, t21, TargetConstant:i32<0>
.This problem is similar to a previously fixed issue #59647 but with different cause.
Minimal Reproduction
https://godbolt.org/z/1jqa7eqK6
Code
Stack Trace