Skip to content

Commit 3ee8d04

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 llvm#151699
1 parent f72c8dc commit 3ee8d04

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,12 @@ class InstructionsState {
12381238
BinOpSameOpcodeHelper Converter(MainOp);
12391239
if (!Converter.add(I) || !Converter.add(MainOp))
12401240
return nullptr;
1241+
if (!Converter.hasCandidateOpcode(MainOp->getOpcode()) && isAltShuffle()) {
1242+
BinOpSameOpcodeHelper AltConverter(AltOp);
1243+
if (AltConverter.add(I) && AltConverter.add(AltOp) &&
1244+
AltConverter.hasCandidateOpcode(AltOp->getOpcode()))
1245+
return AltOp;
1246+
}
12411247
if (Converter.hasAltOp() && !isAltShuffle())
12421248
return nullptr;
12431249
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)