Skip to content

Commit c73f425

Browse files
[Attributor] Add AAValueSimplifyCallSiteArgument::manifest
Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D82861
1 parent 02cfa75 commit c73f425

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,6 +4670,30 @@ struct AAValueSimplifyCallSiteArgument : AAValueSimplifyFloating {
46704670
AAValueSimplifyCallSiteArgument(const IRPosition &IRP, Attributor &A)
46714671
: AAValueSimplifyFloating(IRP, A) {}
46724672

4673+
/// See AbstractAttribute::manifest(...).
4674+
ChangeStatus manifest(Attributor &A) override {
4675+
ChangeStatus Changed = ChangeStatus::UNCHANGED;
4676+
4677+
if (SimplifiedAssociatedValue.hasValue() &&
4678+
!SimplifiedAssociatedValue.getValue())
4679+
return Changed;
4680+
4681+
Value &V = getAssociatedValue();
4682+
auto *C = SimplifiedAssociatedValue.hasValue()
4683+
? dyn_cast<Constant>(SimplifiedAssociatedValue.getValue())
4684+
: UndefValue::get(V.getType());
4685+
if (C) {
4686+
Use &U = cast<CallBase>(&getAnchorValue())->getArgOperandUse(getArgNo());
4687+
// We can replace the AssociatedValue with the constant.
4688+
if (&V != C && V.getType() == C->getType()) {
4689+
if (A.changeUseAfterManifest(U, *C))
4690+
Changed = ChangeStatus::CHANGED;
4691+
}
4692+
}
4693+
4694+
return Changed | AAValueSimplify::manifest(A);
4695+
}
4696+
46734697
void trackStatistics() const override {
46744698
STATS_DECLTRACK_CSARG_ATTR(value_simplify)
46754699
}

llvm/test/Transforms/Attributor/range.ll

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,71 @@ end:
10631063
}
10641064

10651065

1066+
define i32 @func(i1 %c) {
1067+
; CHECK-LABEL: define {{[^@]+}}@func
1068+
; CHECK-SAME: (i1 [[C:%.*]])
1069+
; CHECK-NEXT: [[RET:%.*]] = select i1 [[C]], i32 0, i32 1
1070+
; CHECK-NEXT: ret i32 [[RET]]
1071+
;
1072+
%ret = select i1 %c, i32 0, i32 1
1073+
ret i32 %ret
1074+
}
1075+
1076+
define i32 @simplify_callsite_argument(i1 %d) {
1077+
; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@simplify_callsite_argument
1078+
; IS__TUNIT_OPM-SAME: (i1 [[D:%.*]])
1079+
; IS__TUNIT_OPM-NEXT: [[C:%.*]] = select i1 [[D]], i1 true, i1 false
1080+
; IS__TUNIT_OPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
1081+
; IS__TUNIT_OPM: t:
1082+
; IS__TUNIT_OPM-NEXT: [[RET1:%.*]] = call i32 @func(i1 [[C]]) #2, !range !3
1083+
; IS__TUNIT_OPM-NEXT: ret i32 [[RET1]]
1084+
; IS__TUNIT_OPM: f:
1085+
; IS__TUNIT_OPM-NEXT: [[RET2:%.*]] = call i32 @func(i1 false) #2, !range !3
1086+
; IS__TUNIT_OPM-NEXT: ret i32 [[RET2]]
1087+
;
1088+
; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@simplify_callsite_argument
1089+
; IS__TUNIT_NPM-SAME: (i1 [[D:%.*]])
1090+
; IS__TUNIT_NPM-NEXT: [[C:%.*]] = select i1 [[D]], i1 true, i1 false
1091+
; IS__TUNIT_NPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
1092+
; IS__TUNIT_NPM: t:
1093+
; IS__TUNIT_NPM-NEXT: [[RET1:%.*]] = call i32 @func(i1 true) #1, !range !4
1094+
; IS__TUNIT_NPM-NEXT: ret i32 [[RET1]]
1095+
; IS__TUNIT_NPM: f:
1096+
; IS__TUNIT_NPM-NEXT: [[RET2:%.*]] = call i32 @func(i1 false) #1, !range !4
1097+
; IS__TUNIT_NPM-NEXT: ret i32 [[RET2]]
1098+
;
1099+
; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@simplify_callsite_argument
1100+
; IS__CGSCC_OPM-SAME: (i1 [[D:%.*]])
1101+
; IS__CGSCC_OPM-NEXT: [[C:%.*]] = select i1 [[D]], i1 true, i1 false
1102+
; IS__CGSCC_OPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
1103+
; IS__CGSCC_OPM: t:
1104+
; IS__CGSCC_OPM-NEXT: [[RET1:%.*]] = call i32 @func(i1 [[C]])
1105+
; IS__CGSCC_OPM-NEXT: ret i32 [[RET1]]
1106+
; IS__CGSCC_OPM: f:
1107+
; IS__CGSCC_OPM-NEXT: [[RET2:%.*]] = call i32 @func(i1 false)
1108+
; IS__CGSCC_OPM-NEXT: ret i32 [[RET2]]
1109+
;
1110+
; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@simplify_callsite_argument
1111+
; IS__CGSCC_NPM-SAME: (i1 [[D:%.*]])
1112+
; IS__CGSCC_NPM-NEXT: [[C:%.*]] = select i1 [[D]], i1 true, i1 false
1113+
; IS__CGSCC_NPM-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
1114+
; IS__CGSCC_NPM: t:
1115+
; IS__CGSCC_NPM-NEXT: [[RET1:%.*]] = call i32 @func(i1 true)
1116+
; IS__CGSCC_NPM-NEXT: ret i32 [[RET1]]
1117+
; IS__CGSCC_NPM: f:
1118+
; IS__CGSCC_NPM-NEXT: [[RET2:%.*]] = call i32 @func(i1 false)
1119+
; IS__CGSCC_NPM-NEXT: ret i32 [[RET2]]
1120+
;
1121+
%c = select i1 %d, i1 true, i1 false
1122+
br i1 %c, label %t, label %f
1123+
t:
1124+
%ret1 = call i32 @func(i1 %c)
1125+
ret i32 %ret1
1126+
f:
1127+
%ret2 = call i32 @func(i1 false)
1128+
ret i32 %ret2
1129+
}
1130+
10661131
!0 = !{i32 0, i32 10}
10671132
!1 = !{i32 10, i32 100}
10681133

0 commit comments

Comments
 (0)