Type *SrcType = Bitcast->getSrcTy();
Type *DstType = Bitcast->getType();
- // Make sure the bitcast doesn't change the number of vector elements.
- if (SrcType->getScalarSizeInBits() == DstType->getScalarSizeInBits()) {
+ // Make sure the bitcast doesn't change between scalar and vector and
+ // doesn't change the number of vector elements.
+ if (SrcType->isVectorTy() == DstType->isVectorTy() &&
+ SrcType->getScalarSizeInBits() == DstType->getScalarSizeInBits()) {
// Zero-equality and sign-bit checks are preserved through sitofp + bitcast.
Value *X;
if (match(BCSrcOp, m_SIToFP(m_Value(X)))) {
%cmp = icmp eq i96 %b, 0
ret i1 %cmp
}
+
+; Don't crash trying to fold scalar <-> vector bitcast.
+
+define <1 x i1> @PR55516(i64 %x) {
+; CHECK-LABEL: @PR55516(
+; CHECK-NEXT: [[T0:%.*]] = sitofp i64 [[X:%.*]] to double
+; CHECK-NEXT: [[BC:%.*]] = bitcast double [[T0]] to <1 x i64>
+; CHECK-NEXT: [[R:%.*]] = icmp eq <1 x i64> [[BC]], zeroinitializer
+; CHECK-NEXT: ret <1 x i1> [[R]]
+;
+ %t0 = sitofp i64 %x to double
+ %bc = bitcast double %t0 to <1 x i64>
+ %r = icmp eq <1 x i64> %bc, zeroinitializer
+ ret <1 x i1> %r
+}
+
+define i1 @PR55516_alt(<1 x i64> %x) {
+; CHECK-LABEL: @PR55516_alt(
+; CHECK-NEXT: [[TMP1:%.*]] = extractelement <1 x i64> [[X:%.*]], i64 0
+; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[TMP1]], 0
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %t0 = sitofp <1 x i64> %x to <1 x double>
+ %bc = bitcast <1 x double> %t0 to i64
+ %r = icmp eq i64 %bc, zeroinitializer
+ ret i1 %r
+}