Skip to content

Commit 301880c

Browse files
committed
[FuncSpec] Handle ssa_copy intrinsic calls in InstCostVisitor
Look through ssa_copy intrinsic calls when computing codesize bonus for a specialization. Also remove redundant logic to skip computing codesize bonus for ssa_copy intrinsics, now these are considered zero-cost by TTI (in PR#75294).
1 parent acfdc09 commit 301880c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ Cost InstCostVisitor::estimateBasicBlocks(
120120
continue;
121121

122122
for (Instruction &I : *BB) {
123-
// Disregard SSA copies.
124-
if (auto *II = dyn_cast<IntrinsicInst>(&I))
125-
if (II->getIntrinsicID() == Intrinsic::ssa_copy)
126-
continue;
127123
// If it's a known constant we have already accounted for it.
128124
if (KnownConstants.contains(&I))
129125
continue;
@@ -402,6 +398,14 @@ Constant *InstCostVisitor::visitFreezeInst(FreezeInst &I) {
402398
}
403399

404400
Constant *InstCostVisitor::visitCallBase(CallBase &I) {
401+
assert(LastVisited != KnownConstants.end() && "Invalid iterator!");
402+
403+
// Look through calls to ssa_copy intrinsics.
404+
if (auto *II = dyn_cast<IntrinsicInst>(&I);
405+
II && II->getIntrinsicID() == Intrinsic::ssa_copy) {
406+
return LastVisited->second;
407+
}
408+
405409
Function *F = I.getCalledFunction();
406410
if (!F || !canConstantFoldCallTo(&I, F))
407411
return nullptr;

llvm/test/Transforms/FunctionSpecialization/ssa-copy.ll

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
; Verify that we are able to estimate the codesize savings by looking through
99
; calls to ssa_copy intrinsics, which are inserted by PredicateInfo when IPSCCP
1010
; is run prior to FunctionSpecialization.
11-
; FIXME: We should be able to specialize this, but we currently do not handle
12-
; FIXME: llvm.ssa.copy calls in InstCostVisitor.
1311
define i32 @main() {
1412
entry:
1513
%res = call i32 @test_ssa_copy(i32 0)
@@ -43,10 +41,10 @@ exit4:
4341
ret i32 999
4442
}
4543

46-
; CHECK-LABEL: define range(i32 1, 0) i32 @main() {
44+
; CHECK-LABEL: define i32 @main() {
4745
; CHECK-NEXT: [[ENTRY:.*:]]
48-
; CHECK-NEXT: [[RES:%.*]] = call i32 @test_ssa_copy(i32 0)
49-
; CHECK-NEXT: ret i32 [[RES]]
46+
; CHECK-NEXT: [[RES:%.*]] = call i32 @test_ssa_copy.specialized.1(i32 0)
47+
; CHECK-NEXT: ret i32 999
5048
;
5149
;
5250
; CHECK-LABEL: define range(i32 1, 0) i32 @test_ssa_copy(
@@ -65,3 +63,17 @@ exit4:
6563
; CHECK: [[EXIT4]]:
6664
; CHECK-NEXT: ret i32 999
6765
;
66+
;
67+
; CHECK-LABEL: define internal i32 @test_ssa_copy.specialized.1(
68+
; CHECK-SAME: i32 [[X:%.*]]) {
69+
; CHECK-NEXT: [[ENTRY:.*:]]
70+
; CHECK-NEXT: br label %[[BLOCK1:.*]]
71+
; CHECK: [[BLOCK1]]:
72+
; CHECK-NEXT: br label %[[BLOCK2:.*]]
73+
; CHECK: [[BLOCK2]]:
74+
; CHECK-NEXT: br label %[[BLOCK3:.*]]
75+
; CHECK: [[BLOCK3]]:
76+
; CHECK-NEXT: br label %[[EXIT4:.*]]
77+
; CHECK: [[EXIT4]]:
78+
; CHECK-NEXT: ret i32 poison
79+
;

0 commit comments

Comments
 (0)