Skip to content

Commit 7bcb1c9

Browse files
committed
Fix hasOneUse check to only consider shuffles
1 parent 8cf0455 commit 7bcb1c9

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,11 @@ InstCombinerImpl::foldShuffledIntrinsicOperands(IntrinsicInst *II) {
14241424
!match(NonConstArg, m_Shuffle(m_Value(X), m_Poison(), m_Mask(Mask))))
14251425
return nullptr;
14261426

1427-
// At least 1 operand must have 1 use because we are creating 2 instructions.
1428-
if (none_of(II->args(), [](Value *V) { return V->hasOneUse(); }))
1427+
// At least 1 operand must be a shuffle with 1 use because we are creating 2
1428+
// instructions.
1429+
if (none_of(II->args(), [](Value *V) {
1430+
return isa<ShuffleVectorInst>(V) && V->hasOneUse();
1431+
}))
14291432
return nullptr;
14301433

14311434
// See if all arguments are shuffled with the same mask.

llvm/test/Transforms/InstCombine/minmax-intrinsics.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,21 @@ define <3 x i8> @smin_unary_shuffle_ops_uses(<3 x i8> %x, <3 x i8> %y) {
25112511
ret <3 x i8> %r
25122512
}
25132513

2514+
; negative test - too many uses
2515+
2516+
define <3 x i8> @smin_unary_shuffle_ops_uses_const(<3 x i8> %x, <3 x i8> %y) {
2517+
; CHECK-LABEL: @smin_unary_shuffle_ops_uses_const(
2518+
; CHECK-NEXT: [[SX:%.*]] = shufflevector <3 x i8> [[X:%.*]], <3 x i8> poison, <3 x i32> <i32 1, i32 0, i32 2>
2519+
; CHECK-NEXT: call void @use_vec(<3 x i8> [[SX]])
2520+
; CHECK-NEXT: [[R:%.*]] = call <3 x i8> @llvm.smin.v3i8(<3 x i8> [[SX]], <3 x i8> <i8 1, i8 2, i8 3>)
2521+
; CHECK-NEXT: ret <3 x i8> [[R]]
2522+
;
2523+
%sx = shufflevector <3 x i8> %x, <3 x i8> poison, <3 x i32> <i32 1, i32 0, i32 2>
2524+
call void @use_vec(<3 x i8> %sx)
2525+
%r = call <3 x i8> @llvm.smin.v3i8(<3 x i8> %sx, <3 x i8> <i8 1, i8 2, i8 3>)
2526+
ret <3 x i8> %r
2527+
}
2528+
25142529
; This would assert/crash because we tried to zext to i1.
25152530

25162531
@g = external dso_local global i32, align 4

llvm/test/Transforms/InstCombine/powi.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,7 @@ define <3 x float> @powi_unary_shuffle_ops_use(<3 x float> %x, i32 %power, ptr %
582582
; CHECK-LABEL: @powi_unary_shuffle_ops_use(
583583
; CHECK-NEXT: [[SX:%.*]] = shufflevector <3 x float> [[X:%.*]], <3 x float> poison, <3 x i32> <i32 1, i32 0, i32 2>
584584
; CHECK-NEXT: store <3 x float> [[SX]], ptr [[P:%.*]], align 16
585-
; CHECK-NEXT: [[TMP1:%.*]] = call <3 x float> @llvm.powi.v3f32.i32(<3 x float> [[X]], i32 [[POWER:%.*]])
586-
; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[TMP1]], <3 x float> poison, <3 x i32> <i32 1, i32 0, i32 2>
585+
; CHECK-NEXT: [[R:%.*]] = call <3 x float> @llvm.powi.v3f32.i32(<3 x float> [[SX]], i32 [[POWER:%.*]])
587586
; CHECK-NEXT: ret <3 x float> [[R]]
588587
;
589588
%sx = shufflevector <3 x float> %x, <3 x float> poison, <3 x i32> <i32 1, i32 0, i32 2>

0 commit comments

Comments
 (0)