Skip to content

Commit 660475b

Browse files
committed
Fix shl crash
1 parent 689b762 commit 660475b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,8 +2269,10 @@ Instruction *InstCombinerImpl::foldVectorBinop(BinaryOperator &Inst) {
22692269
// It may not be safe to execute a binop on a vector with poison elements
22702270
// because the entire instruction can be folded to undef or create poison
22712271
// that did not exist in the original code.
2272+
// This isn't needed for scalable vectors since they're always splats.
22722273
// TODO: The shift case should not be necessary.
2273-
if (Inst.isIntDivRem() || (Inst.isShift() && ConstOp1))
2274+
if (isa<FixedVectorType>(V1->getType()) &&
2275+
(Inst.isIntDivRem() || (Inst.isShift() && ConstOp1)))
22742276
NewC = getSafeVectorConstantForBinop(Opcode, NewC, ConstOp1);
22752277

22762278
// Op(shuffle(V1, Mask), C) -> shuffle(Op(V1, NewC), Mask)

llvm/test/Transforms/InstCombine/vec_shuffle.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,28 @@ define <2 x i32> @shl_splat_constant1(<2 x i32> %x) {
938938
ret <2 x i32> %r
939939
}
940940

941+
define <vscale x 2 x i32> @shl_splat_constant0_scalable(<vscale x 2 x i32> %x) {
942+
; CHECK-LABEL: @shl_splat_constant0_scalable(
943+
; CHECK-NEXT: [[TMP1:%.*]] = shl <vscale x 2 x i32> splat (i32 5), [[X:%.*]]
944+
; CHECK-NEXT: [[R:%.*]] = shufflevector <vscale x 2 x i32> [[TMP1]], <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
945+
; CHECK-NEXT: ret <vscale x 2 x i32> [[R]]
946+
;
947+
%splat = shufflevector <vscale x 2 x i32> %x, <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer
948+
%r = shl <vscale x 2 x i32> splat (i32 5), %splat
949+
ret <vscale x 2 x i32> %r
950+
}
951+
952+
define <vscale x 2 x i32> @shl_splat_constant1_scalable(<vscale x 2 x i32> %x) {
953+
; CHECK-LABEL: @shl_splat_constant1_scalable(
954+
; CHECK-NEXT: [[TMP1:%.*]] = shl <vscale x 2 x i32> [[X:%.*]], splat (i32 5)
955+
; CHECK-NEXT: [[R:%.*]] = shufflevector <vscale x 2 x i32> [[TMP1]], <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
956+
; CHECK-NEXT: ret <vscale x 2 x i32> [[R]]
957+
;
958+
%splat = shufflevector <vscale x 2 x i32> %x, <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer
959+
%r = shl <vscale x 2 x i32> %splat, splat (i32 5)
960+
ret <vscale x 2 x i32> %r
961+
}
962+
941963
define <2 x i32> @ashr_splat_constant0(<2 x i32> %x) {
942964
; CHECK-LABEL: @ashr_splat_constant0(
943965
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> <i32 5, i32 poison>, [[X:%.*]]

0 commit comments

Comments
 (0)