Skip to content

Commit d1e3d20

Browse files
committed
[Scalarizer] Fix to only scalarize if intrinsic was marked as isTriviallyScalarizable
fixes #113624
1 parent 8aa69a0 commit d1e3d20

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Transforms/Scalar/Scalarizer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,16 @@ bool ScalarizerVisitor::visitExtractValueInst(ExtractValueInst &EVI) {
10841084
ValueVector Res;
10851085
if (!isStructOfMatchingFixedVectors(OpTy))
10861086
return false;
1087+
if (CallInst *CI = dyn_cast<CallInst>(Op)) {
1088+
Function *F = CI->getCalledFunction();
1089+
if (!F)
1090+
return false;
1091+
Intrinsic::ID ID = F->getIntrinsicID();
1092+
if (ID == Intrinsic::not_intrinsic || !isTriviallyScalarizable(ID))
1093+
return false;
1094+
// Note: Only proceed if Operand is a`CallInst` and it is defined in `isTriviallyScalarizable`.
1095+
} else
1096+
return false;
10871097
Type *VecType = cast<FixedVectorType>(OpTy->getContainedType(0));
10881098
std::optional<VectorSplit> VS = getVectorSplit(VecType);
10891099
if (!VS)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt %s -passes='function(scalarizer)' -S | FileCheck %s
3+
4+
; Test to make sure that struct return intrinsics that are not `isTriviallyScalarizable` do not get scalarized.
5+
6+
define <3 x i32> @test_(<3 x i32> %a, <3 x i32> %b) {
7+
; CHECK-LABEL: define <3 x i32> @test_(
8+
; CHECK-SAME: <3 x i32> [[A:%.*]], <3 x i32> [[B:%.*]]) {
9+
; CHECK-NEXT: [[R:%.*]] = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> [[B]], <3 x i32> [[B]])
10+
; CHECK-NEXT: [[EL:%.*]] = extractvalue { <3 x i32>, <3 x i1> } [[R]], 0
11+
; CHECK-NEXT: ret <3 x i32> [[EL]]
12+
;
13+
%r = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %b, <3 x i32> %b)
14+
%el = extractvalue { <3 x i32>, <3 x i1> } %r, 0
15+
ret <3 x i32> %el
16+
}

0 commit comments

Comments
 (0)