Skip to content

Commit e3463ee

Browse files
committed
llvm-reduce: Fix overly conservative operands-to-args user restriction
I assume this was a leftover from typed pointers. It's easier to replace the non-callee uses, they are just replacable pointer values.
1 parent 54385f5 commit e3463ee

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

llvm/test/tools/llvm-reduce/operands-to-args.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ define void @f(ptr %a) {
7777
@gv_init_use = global [1 x ptr] [ptr @has_global_init_user]
7878

7979
; INTERESTING-LABEL: define void @has_global_init_user(
80-
; REDUCED-LABEL: define void @has_global_init_user() {
80+
; REDUCED-LABEL: define void @has_global_init_user(ptr %Local) {
8181
define void @has_global_init_user() {
8282
%Local = alloca i32, align 4
8383
store i32 42, ptr %Local, align 4
8484
ret void
8585
}
8686

8787
; INTERESTING-LABEL: define void @has_callee_and_arg_user(
88-
; REDUCED-LABEL: define void @has_callee_and_arg_user(ptr %orig.arg) {
88+
; REDUCED-LABEL: define void @has_callee_and_arg_user(ptr %orig.arg, ptr %Local) {
8989
define void @has_callee_and_arg_user(ptr %orig.arg) {
9090
%Local = alloca i32, align 4
9191
store i32 42, ptr %Local, align 4
@@ -96,7 +96,7 @@ declare void @ptr_user(ptr)
9696

9797
; INTERESTING-LABEL: define void @calls_and_passes_func(
9898
; REDUCED-LABEL: define void @calls_and_passes_func(ptr %has_callee_and_arg_user) {
99-
; REDUCED: call void @has_callee_and_arg_user(ptr %has_callee_and_arg_user)
99+
; REDUCED: call void @has_callee_and_arg_user(ptr %has_callee_and_arg_user, ptr null)
100100
define void @calls_and_passes_func() {
101101
call void @has_callee_and_arg_user(ptr @has_callee_and_arg_user)
102102
ret void

llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919

2020
using namespace llvm;
2121

22-
static bool canReplaceFunction(Function *F) {
23-
return all_of(F->uses(), [](Use &Op) {
24-
if (auto *CI = dyn_cast<CallBase>(Op.getUser()))
25-
return &CI->getCalledOperandUse() == &Op;
26-
return false;
27-
});
22+
static bool canReplaceFunction(const Function &F) {
23+
// TODO: Add controls to avoid ABI breaks (e.g. don't break main)
24+
return true;
2825
}
2926

3027
static bool canReduceUse(Use &Op) {
@@ -59,8 +56,9 @@ static bool canReduceUse(Use &Op) {
5956
static void replaceFunctionCalls(Function *OldF, Function *NewF) {
6057
SmallVector<CallBase *> Callers;
6158
for (Use &U : OldF->uses()) {
62-
auto *CI = cast<CallBase>(U.getUser());
63-
assert(&U == &CI->getCalledOperandUse());
59+
auto *CI = dyn_cast<CallBase>(U.getUser());
60+
if (!CI || !CI->isCallee(&U)) // RAUW can handle these fine.
61+
continue;
6462

6563
Function *CalledF = CI->getCalledFunction();
6664
if (CalledF == OldF) {
@@ -209,7 +207,7 @@ void llvm::reduceOperandsToArgsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
209207

210208
SmallVector<Use *> OperandsToReduce;
211209
for (Function &F : make_early_inc_range(Program.functions())) {
212-
if (!canReplaceFunction(&F))
210+
if (!canReplaceFunction(F))
213211
continue;
214212
OperandsToReduce.clear();
215213
for (Instruction &I : instructions(&F)) {

0 commit comments

Comments
 (0)