This is an archive of the discontinued LLVM Phabricator instance.

[llvm-reduce] Don't delete arguments of intrinsics
ClosedPublic

Authored by langston-barrett on May 25 2021, 5:24 PM.

Details

Summary

The argument reduction pass shouldn't remove arguments of
intrinsics, because the resulting module is ill-formed, and so
inherently uninteresting.

Diff Detail

Event Timeline

langston-barrett requested review of this revision.May 25 2021, 5:24 PM
langston-barrett created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2021, 5:24 PM

should we be skipping all intrinsics? intrinsic signatures should never change right?

and there are a couple comments that seem to indicate that we are only touching definitions, but it looks like we're also touching declarations

llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
10

drive by, this looks wrong

111–112

drive by, this looks wrong

Generalize to all intrinsics

should we be skipping all intrinsics? intrinsic signatures should never change right?

Good call, I've generalized this patch.

and there are a couple comments that seem to indicate that we are only touching definitions, but it looks like we're also touching declarations

Agreed.

lebedev.ri requested changes to this revision.May 26 2021, 9:01 AM
lebedev.ri added a reviewer: lebedev.ri.
lebedev.ri added a subscriber: lebedev.ri.

I'm not okay with blankedly ignoring intrinsics.
Please can you show the malformed IR after dbginfo arg removal?

why wouldn't we always ignore intrinsics? their signature is always the same, it should be invalid to remove a parameter of an intrinsic

Please can you show the malformed IR after dbginfo arg removal?

Here's the output of the testcase I added before this patch:

******************** TEST 'LLVM :: tools/llvm-reduce/remove-args-dbg-intrinsics.ll' FAILED ********************
Script:
--
: 'RUN: at line 3';   llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments --test=/home/langston/code/llvm-project/build/bin/opt --test-arg=-verify --test-arg=-disable-output --output=/home/langston/code/llvm-project/build/test/tools/llvm-reduce/Output/remove-args-dbg-intrinsics.ll.tmp /home/langston/code/llvm-project/llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
: 'RUN: at line 4';   cat /home/langston/code/llvm-project/build/test/tools/llvm-reduce/Output/remove-args-dbg-intrinsics.ll.tmp | /home/langston/code/llvm-project/build/bin/FileCheck /home/langston/code/llvm-project/llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
--
Exit Code: 1

Command Output (stdout):
--
*** Reducing Arguments...
----------------------------
Param Index Reference:
  llvm.dbg.addr
	1: 
	2: 
	3: 
----------------------------
  llvm.dbg.declare
	4: 
	5: 
	6: 
----------------------------
  llvm.dbg.value
	7: 
	8: 
	9: 
----------------------------

--
Command Output (stderr):
--
Invalid user of intrinsic instruction!
void (metadata, metadata, metadata)* bitcast (void ()* @llvm.dbg.addr to void (metadata, metadata, metadata)*)
Invalid user of intrinsic instruction!
void (metadata, metadata, metadata)* bitcast (void ()* @llvm.dbg.declare to void (metadata, metadata, metadata)*)
Invalid user of intrinsic instruction!
void (metadata, metadata, metadata)* bitcast (void ()* @llvm.dbg.value to void (metadata, metadata, metadata)*)
Invalid reduction

--

********************
********************
Failed Tests (1):
  LLVM :: tools/llvm-reduce/remove-args-dbg-intrinsics.ll

If I run that same command without --abort-on-invalid-reduction, I just see many more WARNINGs, and the final module is identical to the input module. So IIUC, this patch doesn't result in different output from llvm-reduce, just fewer unnecessary *attempts* at reduction.

the title/summary needs to be updated

llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
4

I don't think this is the right test, llvm-reduce already checks that something is verified. The test should be checking that each of the three intrinsics is declared (ignoring the arguments). Look at the other tests in the file for more examples.

llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
47

F.isIntrinsic()

lebedev.ri added inline comments.May 26 2021, 12:12 PM
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
47

While i could be okay with ignoring actual intriniscs,
i'm not sure why we need to ignore all functions starting with @llvm..

aeubanks added inline comments.May 26 2021, 12:14 PM
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
47

https://llvm.org/docs/LangRef.html#intrinsic-functions
Intrinsic function names must all start with an “llvm.” prefix. This prefix is reserved in LLVM for intrinsic names; thus, function names may not begin with this prefix.

langston-barrett retitled this revision from [llvm-reduce] Don't delete arguments of debug intrinsics to [llvm-reduce] Don't delete arguments of intrinsics.May 26 2021, 12:51 PM
langston-barrett edited the summary of this revision. (Show Details)

Use FileCheck instead of opt as the interestingness test

Use Function::isIntrinsic instead of Function::getIntrinsicID

could you also update the various comments to say that all functions, not just definitions, are touched?

llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll
4

I think this is still not quite right.
The llvm-reduce test should only be checking for the names of the functions, whereas the final test should check that everything is there. Other tests do something similar (e.g. remove-dso-local.ll)

so something like

CHECK-INTERESTINGNESS: declare void @llvm.dbg.addr
CHECK-INTERESTINGNESS: declare void @llvm.dbg.declare
CHECK-INTERESTINGNESS: declare void @llvm.dbg.value

CHECK-FINAL: declare void @llvm.dbg.addr(metadata, metadata, metadata)
CHECK-FINAL: declare void @llvm.dbg.declare(metadata, metadata, metadata)
CHECK-FINAL: declare void @llvm.dbg.value(metadata, metadata, metadata)

Improve tests (thanks for suggestions, @aeubanks)

Fix comments about only working on defined functions

the displayed diff is only the latest diff

Maybe fix uploaded diff (I'm new to Phabricator)

Probably fix uploaded diff?

aeubanks accepted this revision.Jun 21 2021, 10:30 AM

lgtm, thanks!

This revision is now accepted and ready to land.Jun 21 2021, 10:30 AM

lgtm, thanks!

Thanks for your patience and comments in the review! I don't have commit access, so I'll need some help merging this.

no problem, will do

This revision was automatically updated to reflect the committed changes.