This is an archive of the discontinued LLVM Phabricator instance.

[AggressiveInstCombine] Add `phi` nodes support to `TruncInstCombine`
ClosedPublic

Authored by anton-afanasyev on Sep 15 2021, 2:44 AM.

Diff Detail

Event Timeline

anton-afanasyev requested review of this revision.Sep 15 2021, 2:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2021, 2:44 AM

Ping.
Though this patch makes AIC more complicated (using general graph instead of expression DAG), it spreads AIC outside one BB. It impacts ~30 tests of test suite.

Ping.
Though this patch makes AIC more complicated (using general graph instead of expression DAG), it spreads AIC outside one BB. It impacts ~30 tests of test suite.

Are there any notable diffs (codegen/perf) in those tests?

Ping.
Though this patch makes AIC more complicated (using general graph instead of expression DAG), it spreads AIC outside one BB. It impacts ~30 tests of test suite.

Are there any notable diffs (codegen/perf) in those tests?

I don't think that such diffs could be called "notable", what I see is rather controversal impact in code size:

$ ~/llvm/test-suite/utils/compare.py -a --filter-short -m size..text result_base.json vs result_exp.json
Tests: 2889
Short Running: 465 (filtered out)
Remaining: 2424
Metric: size..text

Program                                        lhs        rhs        diff 
 test-suite.../Benchmarks/Ptrdist/bc/bc.test   46658.00   46722.00    0.1%
 test-suite...terchange/LoopInterchange.test   232802.00  232818.00   0.0%
 test-suite...eProcessing/Dilate/Dilate.test   236098.00  236114.00   0.0%
 test-suite...Filtering/BilateralFilter.test   236498.00  236514.00   0.0%
 test-suite...sion/AnisotropicDiffusion.test   237202.00  237218.00   0.0%
 test-suite.../Builtins/Int128/Builtins.test   237218.00  237234.00   0.0%
 test-suite...terpolation/Interpolation.test   237458.00  237474.00   0.0%
 test-suite...ImageProcessing/Blur/blur.test   239058.00  239074.00   0.0%
 test-suite...eProcessing/Dither/Dither.test   239842.00  239858.00   0.0%
 test-suite...oBenchmarks/harris/harris.test   241122.00  241138.00   0.0%
 test-suite...LPVectorizationBenchmarks.test   256626.00  256642.00   0.0%
 test-suite...opVectorizationBenchmarks.test   353330.00  353346.00   0.0%
 test-suite...MemFunctions/MemFunctions.test   371794.00  371810.00   0.0%
 test-suite...SubsetBRawLoops/lcalsBRaw.test   421026.00  421042.00   0.0%
 test-suite...BLambdaLoops/lcalsBLambda.test   421282.00  421298.00   0.0%
 test-suite...SubsetARawLoops/lcalsARaw.test   430978.00  430994.00   0.0%
 test-suite...ALambdaLoops/lcalsALambda.test   432050.00  432066.00   0.0%
 test-suite...CLambdaLoops/lcalsCLambda.test   434514.00  434530.00   0.0%
 test-suite...SubsetCRawLoops/lcalsCRaw.test   434690.00  434706.00   0.0%
 test-suite...ications/JM/lencod/lencod.test   756738.00  756754.00   0.0%
 test-suite...itcode/Regression/fft/fft.test   7425490.00 7425522.00  0.0%
 test-suite...ute/GCC-C-execute-loop-13.test   546.00     546.00      0.0%
...
 test-suite.../GCC-C-execute-20000403-1.test   450.00     450.00      0.0%
 test-suite...lications/ClamAV/clamscan.test   531321.00  531289.00  -0.0%
 test-suite...nsumer-lame/consumer-lame.test   175042.00  175026.00  -0.0%
 test-suite...nsumer-jpeg/consumer-jpeg.test   167186.00  167170.00  -0.0%
 test-suite...pplications/oggenc/oggenc.test   252210.00  252162.00  -0.0%
 test-suite...lications/sqlite3/sqlite3.test   496770.00  496530.00  -0.0%
 test-suite...ests/Vectorizer/gcc-loops.test   21330.00   21314.00   -0.1%
 test-suite...s/MallocBench/cfrac/cfrac.test   20754.00   20722.00   -0.2%
 test-suite...itBench/uudecode/uudecode.test   1538.00    1522.00    -1.0%
 Geomean difference                                                  -0.0%

Therefore I would abandon this change until we see a strict need of it.

I would recommend to proceed with this.

None of those size changes look like alarming - why do you want to stop work on this patch?

I would recommend to proceed with this.

None of those size changes look like alarming - why do you want to stop work on this patch?

The patch changes previous logic without undoubted positive impact. I would expect no code size increase of any test for such change. But ok, I'm to investigate what is a real cause of it and proceed with this.

@anton-afanasyev Now that 14.x has been branched are you intending to revive this?

I've investigated small regressions, caused by this patch. The sizes are actually increased at the backend level, while translating llvm to machine code, for instanse:

> ll symtab.c.*
13769 symtab.c.base.ll
13681 symtab.c.exp.ll
8280 symtab.c.base.s
8394 symtab.c.exp.s

For the tests from testsuite this mostly leads to just +16 bytes code size increase (see table at D109817#3184752), so I believe it's acceptable fluctuation.

I would recommend to proceed with this.

@lebedev.ri Are you still happy with this patch?

I would recommend to proceed with this.

@lebedev.ri Are you still happy with this patch?

Conceptually, yes.
Are there tests with switches, where the PHI node has multiple incoming edges from the same predecessor?

llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
160

Stack should be a SetVector then.
Also, could use a comment.

anton-afanasyev marked an inline comment as done.Feb 14 2022, 10:54 AM

Are there tests with switches, where the PHI node has multiple incoming edges from the same predecessor?

What do you mean by "the same predecessor"? There is test with ordinary loop.

llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
160

Stack is already used as stack, we need to push/pop from it.
Added comment.

anton-afanasyev marked an inline comment as done.

Add comment

Are there tests with switches, where the PHI node has multiple incoming edges from the same predecessor?

What do you mean by "the same predecessor"? There is test with ordinary loop.

https://godbolt.org/z/MdsrzGnvq

Are there tests with switches, where the PHI node has multiple incoming edges from the same predecessor?

What do you mean by "the same predecessor"? There is test with ordinary loop.

https://godbolt.org/z/MdsrzGnvq

Oh, I see. Added test.

lebedev.ri accepted this revision.Feb 23 2022, 1:47 AM

Sorry, meant to take another look and forgot.
Seems reasonable, let's see who complains :)

This revision is now accepted and ready to land.Feb 23 2022, 1:47 AM
This revision was landed with ongoing or failed builds.Feb 23 2022, 3:02 AM
This revision was automatically updated to reflect the committed changes.

Fix sanitizer breakage: erase phi-nodes from InstInfoMap before erasing themselves

lebedev.ri reopened this revision.Feb 25 2022, 12:46 AM

Fix sanitizer breakage: erase phi-nodes from InstInfoMap before erasing themselves

(If you believe that fixes the issue then feel free to recommit, no further feedback here expected)

This revision is now accepted and ready to land.Feb 25 2022, 12:46 AM

Fix sanitizer breakage: erase phi-nodes from InstInfoMap before erasing themselves

(If you believe that fixes the issue then feel free to recommit, no further feedback here expected)

Sure, I've already recommited this with fix, updated here just to note about it.

This is already closed, reopened accidentally.

Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2022, 8:01 AM

I wrote a ticket about a crash that started happening with this patch:
https://github.com/llvm/llvm-project/issues/58008