Skip to content

Commit d0ea176

Browse files
committed
[SLP]Do not consider SExt/ZExt profitable for demotion, if the user is a bitcast to float
If the user node of the SExt/ZExt node is a bitcast to a float point type, the node itself should not be considered legal to demote, since still the casting is required to match the size of the float point type. Fixes #157277
1 parent 5d550bf commit d0ea176

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21889,6 +21889,10 @@ bool BoUpSLP::collectValuesToDemote(
2188921889
return TryProcessInstruction(BitWidth);
2189021890
case Instruction::ZExt:
2189121891
case Instruction::SExt:
21892+
if (E.UserTreeIndex.UserTE && E.UserTreeIndex.UserTE->hasState() &&
21893+
E.UserTreeIndex.UserTE->getOpcode() == Instruction::BitCast &&
21894+
E.UserTreeIndex.UserTE->getMainOp()->getType()->isFPOrFPVectorTy())
21895+
return false;
2189221896
IsProfitableToDemote = true;
2189321897
return TryProcessInstruction(BitWidth);
2189421898

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 i1 @test(i32 %0) {
5+
; CHECK-LABEL: define i1 @test(
6+
; CHECK-SAME: i32 [[TMP0:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: [[CONV22_I_I:%.*]] = sext i32 [[TMP0]] to i64
9+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i64 [[CONV22_I_I]] to double
10+
; CHECK-NEXT: [[TMP2:%.*]] = fadd double [[TMP1]], 0.000000e+00
11+
; CHECK-NEXT: [[ADD_I_I_I:%.*]] = select i1 false, double 0.000000e+00, double [[TMP2]]
12+
; CHECK-NEXT: [[TMP3:%.*]] = bitcast double [[ADD_I_I_I]] to i64
13+
; CHECK-NEXT: [[CMP3998_I_I:%.*]] = icmp ne i64 [[TMP3]], [[CONV22_I_I]]
14+
; CHECK-NEXT: [[CONV22_1_I_I:%.*]] = sext i32 0 to i64
15+
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i64 [[CONV22_1_I_I]] to double
16+
; CHECK-NEXT: [[TMP5:%.*]] = fadd double [[TMP4]], 0.000000e+00
17+
; CHECK-NEXT: [[ADD_I_1_I_I:%.*]] = select i1 false, double 0.000000e+00, double [[TMP5]]
18+
; CHECK-NEXT: [[TMP6:%.*]] = bitcast double [[ADD_I_1_I_I]] to i64
19+
; CHECK-NEXT: [[CMP3998_1_I_I:%.*]] = icmp ne i64 [[TMP6]], [[CONV22_1_I_I]]
20+
; CHECK-NEXT: ret i1 [[CMP3998_1_I_I]]
21+
;
22+
entry:
23+
%conv22.i.i = sext i32 %0 to i64
24+
%1 = bitcast i64 %conv22.i.i to double
25+
%2 = fadd double %1, 0.000000e+00
26+
%add.i.i.i = select i1 false, double 0.000000e+00, double %2
27+
%3 = bitcast double %add.i.i.i to i64
28+
%cmp3998.i.i = icmp ne i64 %3, %conv22.i.i
29+
%conv22.1.i.i = sext i32 0 to i64
30+
%4 = bitcast i64 %conv22.1.i.i to double
31+
%5 = fadd double %4, 0.000000e+00
32+
%add.i.1.i.i = select i1 false, double 0.000000e+00, double %5
33+
%6 = bitcast double %add.i.1.i.i to i64
34+
%cmp3998.1.i.i = icmp ne i64 %6, %conv22.1.i.i
35+
ret i1 %cmp3998.1.i.i
36+
}

0 commit comments

Comments
 (0)