Skip to content

Commit acef83c

Browse files
[VectorCombine] Fix crash in scalarizeVPIntrinsic (#72039)
When getSplatOp returns nullptr, the intrinsic cannot be scalarized. This patch includes a test case that fixes a crash from trying to scalarize the VPIntrinsic when getSplatOp returns nullptr. This fixes #72034.
1 parent d3d49bc commit acef83c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,13 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
753753
if (!isSplatValue(Op0) || !isSplatValue(Op1))
754754
return false;
755755

756+
// Check getSplatValue early in this function, to avoid doing unnecessary
757+
// work.
758+
Value *ScalarOp0 = getSplatValue(Op0);
759+
Value *ScalarOp1 = getSplatValue(Op1);
760+
if (!ScalarOp0 || !ScalarOp1)
761+
return false;
762+
756763
// For the binary VP intrinsics supported here, the result on disabled lanes
757764
// is a poison value. For now, only do this simplification if all lanes
758765
// are active.
@@ -841,8 +848,6 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
841848
if (!SafeToSpeculate && !isKnownNonZero(EVL, DL, 0, &AC, &VPI, &DT))
842849
return false;
843850

844-
Value *ScalarOp0 = getSplatValue(Op0);
845-
Value *ScalarOp1 = getSplatValue(Op1);
846851
Value *ScalarVal =
847852
ScalarIntrID
848853
? Builder.CreateIntrinsic(VecTy->getScalarType(), *ScalarIntrID,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt -S -mtriple=riscv64 -mattr=+v %s -passes=vector-combine | FileCheck %s --check-prefix=CHECK
3+
4+
declare <4 x i64> @llvm.vp.add.v4i64(<4 x i64>, <4 x i64>, <4 x i1>, i32)
5+
6+
define <4 x i64> @add_v4i64_allonesmask(<4 x i64> %x) {
7+
; CHECK-LABEL: define <4 x i64> @add_v4i64_allonesmask(
8+
; CHECK-SAME: <4 x i64> [[X:%.*]]) #[[ATTR1:[0-9]+]] {
9+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i64> [[X]], <4 x i64> zeroinitializer, <4 x i32> zeroinitializer
10+
; CHECK-NEXT: [[TMP2:%.*]] = call <4 x i64> @llvm.vp.add.v4i64(<4 x i64> [[TMP1]], <4 x i64> zeroinitializer, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, i32 0)
11+
; CHECK-NEXT: ret <4 x i64> [[TMP2]]
12+
;
13+
%1 = shufflevector <4 x i64> %x, <4 x i64> zeroinitializer, <4 x i32> zeroinitializer
14+
%2 = call <4 x i64> @llvm.vp.add.v4i64(<4 x i64> %1, <4 x i64> zeroinitializer, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, i32 0)
15+
ret <4 x i64> %2
16+
}

0 commit comments

Comments
 (0)