[clang] [CIR] -Wreturn-type (1/2): Add an analysis classifying how control reaches a function's end (PR #239774)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 08:57:16 PST 2026


erichkeane wrote:

> I have some (interesting) updates.
> 
> @erichkeane @cor3ntin it happens that CFG skips a lot of things it doesn't need (functions from system headers, Implicitly defined special members, global variable initializers, etc). CIRGen currently emit everything needed for LLVM IR lowering, which means way more work. However, even though it does more, it also misses some, CFG analyze things not emitted by CIRGen too (unused inline functions, uncalled lambdas, etc), so this is a gap we need to fix (which means even more compile time).
> 
> Here's where it gets interesting. Let's assume the baseline is just the CFG, forget LLVM IR for now. Take these two new modes:
> 
>     1. `-fclangir -emit-cir=cirgen` (this PR)
> 
>     2. `-fsyntax-only -fclangir (every body)`: this PR + support for unused inline functions, uncalled lambdas, etc.
> 
>     3. `-fsyntax-only -fclangir (on demand)`: this PR + skips a lot of things needed only for LLVM IR + support for unused inline functions, uncalled lambdas, etc
> 
> 
> I've implemented these two modes (followup 4 and 5, not yet posted). See (in the table below) how (2) increases even further compile time but (3) actually beats CFG, while covering things we don't currently CIRGen. This is probably the direction we want to: (a) if we are looking for analysis only, we do selective CIRGen, or (b) if are looking for analysis + llvm we pay the highest price, or (c) we only pay for what we need for LLVM IR if no analysis is needed.
> TU 	Pipeline 	IR creation (CFG / CIRGen) 	-Wreturn-type (N = num threads)
> CIRDialect.cpp 	`-fsyntax-only` 	152 	17.3
> 	`-fclangir -emit-cir=cirgen` 	1,405 	N=1: 2.7, N=96: 1.8
> 	`-fsyntax-only -fclangir (every body)` 	2,414 	N=1: 12.6, N=96: 9.0
> 	`-fsyntax-only -fclangir (on demand)` 	121 	N=1: 0.6, N=96: 1.2
> OpenACC.cpp 	`-fsyntax-only` 	260 	21.2
> 	`-fclangir -emit-cir=cirgen` 	4,523 	N=1: 12.0, N=96: 6.6
> 	`-fsyntax-only -fclangir (every body)` 	3,737 	N=1: 14.6, N=96: 9.1
> 	`-fsyntax-only -fclangir (on demand)` 	110 	N=1: 0.4, N=96: 1.3
> SLPVectorizer.cpp 	`-fsyntax-only` 	254 	21.6
> 	`-fclangir -emit-cir=cirgen` 	5,434 	N=1: 17.4, N=96: 10.1
> 	`-fsyntax-only -fclangir (every body)` 	3,709 	N=1: 17.0, N=96: 9.6
> 	`-fsyntax-only -fclangir (on demand)` 	228 	N=1: 1.7, N=96: 0.9
> Disasm.cpp 	`-fsyntax-only` 	79 	8.8
> 	`-fclangir -emit-cir=cirgen` 	436 	N=1: 0.6, N=96: 1.1
> 	`-fsyntax-only -fclangir (every body)` 	1,273 	N=1: 6.2, N=96: 4.2
> 	`-fsyntax-only -fclangir (on demand)` 	88 	N=1: 0.4, N=96: 1.1
> OpenMPDialect.cpp 	`-fsyntax-only` 	268 	24.6
> 	`-fclangir -emit-cir=cirgen` 	4,304 	N=1: 11.9, N=96: 4.5
> 	`-fsyntax-only -fclangir (every body)` 	3,957 	N=1: 18.5, N=96: 9.8
> 	`-fsyntax-only -fclangir (on demand)` 	123 	N=1: 0.5, N=96: 1.4
> 
> (p.s. @cor3ntin I'll share LLVM IR numbers with you tomorrow)

Welll interesting....  I would think we need to do the 3 above for our initial version, then perhaps as a 'future direction' figure out how to 'reuse' that output into ClangIR-codegen.  WDYT?   So basically just implement this separate from codegen, even if we end up 'duplicating' work for now.

I'm really impressed we manage to generate 'faster' in 4 of those 5 (IF I'm reading that right, 42-90% improvement, with 1 13% worse)  I'm curious: Do you have any idea why the Disassm.cpp is 'worse'?  Presumably we can be 'better' over time and catch up there, but it is interesting to see.



https://github.com/llvm/llvm-project/pull/239774


More information about the cfe-commits mailing list