Skip to content

Commit e27831f

Browse files
committed
[SLP] Fix a check for main/alternate interchanged instruction
If the instruction is checked for matching the main instruction, need to check if the opcode of the main instruction is compatible with the operands of the instruction. If they are not, need to check the alternate instruction and its operands for compatibility and return alternate instruction as a match. Fixes #151699 Fixed check for non-supported binary operations.
1 parent 66eadbb commit e27831f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,17 @@ class BinOpSameOpcodeHelper {
991991
return Candidate & OrBIT;
992992
case Instruction::Xor:
993993
return Candidate & XorBIT;
994+
case Instruction::LShr:
995+
case Instruction::FAdd:
996+
case Instruction::FSub:
997+
case Instruction::FMul:
998+
case Instruction::SDiv:
999+
case Instruction::UDiv:
1000+
case Instruction::FDiv:
1001+
case Instruction::SRem:
1002+
case Instruction::URem:
1003+
case Instruction::FRem:
1004+
return false;
9941005
default:
9951006
break;
9961007
}
@@ -1238,6 +1249,12 @@ class InstructionsState {
12381249
BinOpSameOpcodeHelper Converter(MainOp);
12391250
if (!Converter.add(I) || !Converter.add(MainOp))
12401251
return nullptr;
1252+
if (isAltShuffle() && !Converter.hasCandidateOpcode(MainOp->getOpcode())) {
1253+
BinOpSameOpcodeHelper AltConverter(AltOp);
1254+
if (AltConverter.add(I) && AltConverter.add(AltOp) &&
1255+
AltConverter.hasCandidateOpcode(AltOp->getOpcode()))
1256+
return AltOp;
1257+
}
12411258
if (Converter.hasAltOp() && !isAltShuffle())
12421259
return nullptr;
12431260
return Converter.hasAltOp() ? AltOp : MainOp;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define i64 @test() {
5+
; CHECK-LABEL: define i64 @test() {
6+
; CHECK-NEXT: [[BB:.*]]:
7+
; CHECK-NEXT: [[SHL:%.*]] = shl i32 0, 1
8+
; CHECK-NEXT: [[ADD1:%.*]] = add i32 0, 1
9+
; CHECK-NEXT: br label %[[BB2:.*]]
10+
; CHECK: [[BB2]]:
11+
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[SHL]], %[[BB]] ]
12+
; CHECK-NEXT: [[PHI3:%.*]] = phi i32 [ 0, %[[BB]] ]
13+
; CHECK-NEXT: [[PHI4:%.*]] = phi i32 [ 0, %[[BB]] ]
14+
; CHECK-NEXT: [[PHI5:%.*]] = phi i32 [ [[ADD1]], %[[BB]] ]
15+
; CHECK-NEXT: ret i64 0
16+
;
17+
bb:
18+
%shl = shl i32 0, 1
19+
%mul = mul i32 0, 0
20+
%add = add i32 0, 0
21+
%add1 = add i32 0, 1
22+
br label %bb2
23+
24+
bb2:
25+
%phi = phi i32 [ %shl, %bb ]
26+
%phi3 = phi i32 [ %add, %bb ]
27+
%phi4 = phi i32 [ %mul, %bb ]
28+
%phi5 = phi i32 [ %add1, %bb ]
29+
ret i64 0
30+
}

0 commit comments

Comments
 (0)