llvm / llvm/llvm-project

Optimization time regression in InstCombinePass

Open
#189,993 0 comments 0 reactions 0 assignees View on GitHub
llvm:instcombine regression slow-compile
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Hello !

I'm currently working on a fork of inNative (to transform wasm to dll), and updating LLVM from 15 to 22.1.2 (and llvm 21 before with the same issue)
Running test on some modules show a regression in the execution time of an optimization pass : `InstCombinePass`
In the original test it was close to +400% (from 200 sec to 1000 sec), and for the minimal repro link to the ticket, the increase reached ~ +100%

Further investigation and flame graph seem to point to the `isAllocSiteRemovable `and its call to `ValueHandleBase::AddToUseList`. Many hit of the profiler fall on the `operator[]` of the DenseMap Handles

The IR generated before the llvm update and after are really close, only flags in IR comments seem to differ. Both are attached to the ticket

In both cases optimization passes are the same, and the number of calls for each of them are the same.

Are you aware of something that has changed around this optimization pass ?

Best regards,
Edalyn Soria

Attachments :
[PassExecTimeComparaison.png](https://github.com/user-attachments/assets/f303ab52-97a1-4484-a567-69e70b6af74e)
[TheIRPreOptim_LLVM15.ir](https://github.com/user-attachments/files/26415713/TheIRPreOptim_LLVM15.txt)
[TheIRPreOptim_LLVM22.ir](https://github.com/user-attachments/files/26415712/TheIRPreOptim_LLVM22.txt)
[TheCppThatIsUsedToCreateTheWasm.cpp](https://github.com/user-attachments/files/26415714/TheCppThatIsUsedToCreateTheWasm.txt)
[FlameGraphLLVM15.png](https://github.com/user-attachments/assets/0f6c7618-e557-4e7d-85fa-703aae06596d)
[FlameGraphLLVM15_visitAlloca.png](https://github.com/user-attachments/assets/d2db289f-872d-436b-973c-2d0c9f139ac9)
[FlameGraphLLVM22.png](https://github.com/user-attachments/assets/95f053c2-6e8f-4e03-8894-de0a6d8883e1)
[FlameGraphLLVM22_AddToUseListCode.png](https://github.com/user-attachments/assets/39865d03-8b1a-44be-8a54-cb857298429d)
[FlameGraphLLVM22_visitAlloca.png](https://github.com/user-attachments/assets/b2ae8d20-2170-4027-9818-8070018c41f0)

edit : adding the custom optimization pass used : [OptimizationPass.cpp](https://github.com/user-attachments/files/26415903/OptimizationPass.txt)

Contributor guide

Open the contributing guide

Research direction

Start by comparing the attached TheIRPreOptim_LLVM15.ir and TheIRPreOptim_LLVM22.ir files, then inspect InstCombinePass around isAllocSiteRemovable and ValueHandleBase::AddToUseList. Use TheCppThatIsUsedToCreateTheWasm.cpp and the attached flame graphs to reproduce and profile the regression; done means identifying the LLVM 15-to-22 change responsible and confirming its optimization-time impact.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.