[RFC] Factoring common pure operations across PHIs / branches to reduce duplicated sqrt calls

Project / Subsystem

gcc / gcc

Date

2026-05-18

Proposer

Guoce Feng <fengguoce@hygon.cn>

Source type

public_inbox

Consensus

Proposed

Sentiment

/10

Technical tradeoffs

  • Factoring out operations may introduce additional overhead if the merged expression is more complex.
  • The transformation needs to ensure the operation is truly side-effect-free and safe to move.
  • Profitability analysis is required to determine whether the transformation results in a net performance gain.

All attributes

project
gcc
subsystem
gcc
patch_id
discussion_id
1106967D-67C5-44CE-8924-03159CA31F1C@hygon.cn
source_type
public_inbox
title
[RFC] Factoring common pure operations across PHIs / branches to reduce duplicated sqrt calls
headline
Proposes factoring common pure operations across PHIs
tldr
Guoce Feng proposes an optimization to factor out common pure operations like `sqrt` across PHIs and branches to reduce redundant calls, especially in vectoriz…
proposer
Guoce Feng <fengguoce@hygon.cn>
consensus
Proposed
outcome
proposed
sentiment_score
technical_tradeoffs
  • Factoring out operations may introduce additional overhead if the merged expression is more complex.
  • The transformation needs to ensure the operation is truly side-effect-free and safe to move.
  • Profitability analysis is required to determine whether the transformation results in a net performance gain.
series_id
series_role
standalone
series_parts
[]
tags
  • optimization
  • SSA
  • PHI nodes
  • vectorization
bugzilla_url
date
2026-05-18T00:00:00.000Z

[RFC] Factoring common pure operations across PHIs / branches to reduce duplicated sqrt calls

Guoce Feng proposes an optimization to factor out common pure operations, such as sqrt, from control-flow joins in GCC. This aims to transform patterns like phi(sqrt(a), sqrt(b), sqrt(c)) into sqrt(phi(a, b, c)) when safe and profitable, potentially reducing redundant calculations in vectorized code. The author seeks guidance on the best implementation approach, considering extending the existing PHI factoring logic or adding a more general common instruction sinking transformation.