Skip to content

Commit 76c8e1d

Browse files
committed
[VectorCombine] Guard against the lane zero select predicate being scalar
All but the first lane was being checked, but this could leave the first lane with a scalar select predicate. This just extends the check to make sure the types are all the same
1 parent 2222fdd commit 76c8e1d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,9 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
19021902
if (CI->getPredicate() != cast<CmpInst>(FrontV)->getPredicate())
19031903
return false;
19041904
if (auto *SI = dyn_cast<SelectInst>(V))
1905-
if (!isa<VectorType>(SI->getOperand(0)->getType()))
1905+
if (!isa<VectorType>(SI->getOperand(0)->getType()) ||
1906+
SI->getOperand(0)->getType() !=
1907+
cast<SelectInst>(FrontV)->getOperand(0)->getType())
19061908
return false;
19071909
if (isa<CallInst>(V) && !isa<IntrinsicInst>(V))
19081910
return false;

llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,4 +993,23 @@ define void @maximal_legal_fpmath(ptr %addr1, ptr %addr2, ptr %result, float %va
993993
ret void
994994
}
995995

996+
define <2 x float> @first_scalar_select(<2 x float> %0, <2 x float> %1, float %x) {
997+
; CHECK-LABEL: @first_scalar_select(
998+
; CHECK-NEXT: entry:
999+
; CHECK-NEXT: [[CMP_I903:%.*]] = fcmp ogt float [[X:%.*]], 0.000000e+00
1000+
; CHECK-NEXT: [[SEL1639:%.*]] = select i1 [[CMP_I903]], <2 x float> [[TMP0:%.*]], <2 x float> [[TMP1:%.*]]
1001+
; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <2 x float> [[TMP0]], zeroinitializer
1002+
; CHECK-NEXT: [[SEL48_I913:%.*]] = select <2 x i1> [[TMP2]], <2 x float> [[TMP0]], <2 x float> [[TMP1]]
1003+
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <2 x float> [[SEL1639]], <2 x float> [[SEL48_I913]], <2 x i32> <i32 0, i32 3>
1004+
; CHECK-NEXT: ret <2 x float> [[TMP3]]
1005+
;
1006+
entry:
1007+
%cmp.i903 = fcmp ogt float %x, 0.000000e+00
1008+
%sel1639 = select i1 %cmp.i903, <2 x float> %0, <2 x float> %1
1009+
%3 = fcmp ogt <2 x float> %0, zeroinitializer
1010+
%sel48.i913 = select <2 x i1> %3, <2 x float> %0, <2 x float> %1
1011+
%4 = shufflevector <2 x float> %sel1639, <2 x float> %sel48.i913, <2 x i32> <i32 0, i32 3>
1012+
ret <2 x float> %4
1013+
}
1014+
9961015
declare void @use(<4 x i8>)

0 commit comments

Comments
 (0)