Skip to content

Commit eae67be

Browse files
committed
Use original return type's element type for return type
Fixes crashes with scmp where the element types aren't necessarily the same.
1 parent bfaacf7 commit eae67be

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,12 @@ InstCombinerImpl::foldShuffledIntrinsicOperands(IntrinsicInst *II) {
14531453

14541454
// intrinsic (shuf X, M), (shuf Y, M), ... --> shuf (intrinsic X, Y, ...), M
14551455
Instruction *FPI = isa<FPMathOperator>(II) ? II : nullptr;
1456+
// Result type might be a different vector width.
1457+
// TODO: Check that the result type isn't widened?
1458+
VectorType *ResTy =
1459+
VectorType::get(II->getType()->getScalarType(), cast<VectorType>(SrcTy));
14561460
Value *NewIntrinsic =
1457-
Builder.CreateIntrinsic(SrcTy, II->getIntrinsicID(), NewArgs, FPI);
1461+
Builder.CreateIntrinsic(ResTy, II->getIntrinsicID(), NewArgs, FPI);
14581462
return new ShuffleVectorInst(NewIntrinsic, Mask);
14591463
}
14601464

llvm/test/Transforms/InstCombine/scmp.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,19 @@ define i8 @scmp_from_select_eq_and_gt_commuted3(i32 %x, i32 %y) {
423423
ret i8 %r
424424
}
425425

426+
define <3 x i2> @scmp_unary_shuffle_ops(<3 x i8> %x, <3 x i8> %y) {
427+
; CHECK-LABEL: define <3 x i2> @scmp_unary_shuffle_ops(
428+
; CHECK-SAME: <3 x i8> [[X:%.*]], <3 x i8> [[Y:%.*]]) {
429+
; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i2> @llvm.scmp.v3i2.v3i8(<3 x i8> [[X]], <3 x i8> [[Y]])
430+
; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i2> [[TMP1]], <3 x i2> poison, <3 x i32> <i32 1, i32 0, i32 2>
431+
; CHECK-NEXT: ret <3 x i2> [[R]]
432+
;
433+
%sx = shufflevector <3 x i8> %x, <3 x i8> poison, <3 x i32> <i32 1, i32 0, i32 2>
434+
%sy = shufflevector <3 x i8> %y, <3 x i8> poison, <3 x i32> <i32 1, i32 0, i32 2>
435+
%r = call <3 x i2> @llvm.scmp(<3 x i8> %sx, <3 x i8> %sy)
436+
ret <3 x i2> %r
437+
}
438+
426439
; Negative test: true value of outer select is not zero
427440
define i8 @scmp_from_select_eq_and_gt_neg1(i32 %x, i32 %y) {
428441
; CHECK-LABEL: define i8 @scmp_from_select_eq_and_gt_neg1(

0 commit comments

Comments
 (0)