Page MenuHomePhabricator

[llvm-reduce] Add reduction passes to reduce operands to undef/1/0
ClosedPublic

Authored by aeubanks on Oct 13 2021, 4:07 PM.

Details

Summary

Having non-undef constants in a final llvm-reduce output is nicer than
having undefs.

This splits the existing reduce-operands pass into three, one which does
the same as the current pass of reducing to undef, and two more to
reduce to the constant 1 and the constant 0. Do not reduce to undef if
the operand is a ConstantData, and do not reduce 0s to 1s.

Reducing GEP operands very frequently causes invalid IR (since types may
not match up if we index differently into a struct), so don't touch GEPs.

Diff Detail

Event Timeline

aeubanks requested review of this revision.Oct 13 2021, 4:07 PM
aeubanks created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2021, 4:07 PM

Thanks for the patch, looks useful to me.

I have a concern in that this will repeatedly replace undef->one->zero->undef->... (if possible) when running the passes multiple times. Ideally, I'd run the reduction passes until no more changes can be applied. This can either be done by comparing the Module before & after a round, or checking whether no pass has applied any chunk while still being interesting. In my experimental setup I am using textual comparison of the dumped Module, so this would not a problem, but think we'd want the latter approach for llvm-reduce.

llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
23–25
37–39
aeubanks updated this revision to Diff 379887.Oct 14 2021, 5:00 PM

address comments
don't replace ConstantData with undef
don't replace 0 with 1

aeubanks edited the summary of this revision. (Show Details)Oct 14 2021, 5:00 PM
Meinersbur accepted this revision.Oct 18 2021, 9:18 PM

LGTM

llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
23

According to the LLVM coding standard, auto is used only in specific cases.

This revision is now accepted and ready to land.Oct 18 2021, 9:18 PM