Skip to content

Conversation

@Stevendeo
Copy link
Contributor

@Stevendeo Stevendeo commented Jul 16, 2025

This PR adds a new --no-local-var option that forces mlang not to define local vars when calculating expressions.
Expressions were compiled as sets of simple binary operations of the form inti = intj || int k;. While this is memory efficient, I believe having the whole expression could lead to some optimizations.

  • C compilers can optimize code with smarter heuristics. For example, when checking the definition of a given variable, the current code calculates all the possible branches while some of them could be simplified quickly (if DC_[A] = 1, then DC_[A] || DC_[B] || DC_[C] || DC_[D] can be evaluated to 1 directly, while int0 = DC_[A] || DC_[B]; int1 = int0 || DC_[C]; int0 = int1 || DC_[D]; requires to calculate everything.)

  • We could simplify boolean expressions with some basic boolean algebra.

Ideally, the --no-local-var option is meant to be temporary. Either the optimization makes the code more efficient and the option becomes the default behavior, or this PR will document why mlang behaves like this.

@Stevendeo Stevendeo changed the base branch from master to extension_correctif July 16, 2025 14:20
@Stevendeo Stevendeo changed the base branch from extension_correctif to master July 16, 2025 14:21
@Stevendeo Stevendeo changed the title No local var option [WIP] No local var option Jul 17, 2025
@Stevendeo Stevendeo force-pushed the no-local-var-option branch 2 times, most recently from da8b397 to d9a8170 Compare July 17, 2025 10:18
@Stevendeo
Copy link
Contributor Author

Stevendeo commented Jul 17, 2025

Résultats des tests via make test_dgfip_c_backend en comparant les temps d'exécution des tests (100 itérations), avec clang v15.0.7 et gcc 13.3.0 (le pourcentage indique l'acceleration que permet l'optimisation, ou la deceleration s'il est négatif) :

  • clang -O1 : +1.72%
  • clang -O2 : -0.85%
  • clang -O3 : +5.95%
  • gcc -O1 : +0.98%
  • gcc -O2 : +5.89%
  • gcc -O3 : +4.70%

@Stevendeo Stevendeo force-pushed the no-local-var-option branch from f5379f8 to 57fee26 Compare July 24, 2025 10:46
@Stevendeo Stevendeo force-pushed the no-local-var-option branch 3 times, most recently from cfbb9a3 to 778b1d3 Compare August 26, 2025 09:11
@Stevendeo Stevendeo changed the title [WIP] No local var option No local var option Sep 11, 2025
@Stevendeo Stevendeo marked this pull request as ready for review September 11, 2025 08:56
@Stevendeo Stevendeo changed the base branch from master to adaptation_correctif November 12, 2025 10:17
@Stevendeo
Copy link
Contributor Author

@david-michel1 La PR a eté rebasée sur adaptation_correctif pour gagner du temps sur le merge, tu peux la review et la merger quand tu veux !

@Stevendeo
Copy link
Contributor Author

J'ai rajouté quelques fix pour que les tests passent mieux - notamment, j'ai corrigé la représentation des binops au niveau compilateur pour limiter la quantité de parentheses, car dans l'état on dépassait les 256 parentheses (ce qui lève un gros flag au moment de la compilation).

@Stevendeo Stevendeo force-pushed the no-local-var-option branch 4 times, most recently from 819d327 to d47d498 Compare November 13, 2025 11:40
@Stevendeo
Copy link
Contributor Author

Les commits suivants sont juste du nettoyage

@Stevendeo Stevendeo force-pushed the no-local-var-option branch 2 times, most recently from 2ac96fa to bcabe44 Compare November 26, 2025 11:18
@Stevendeo Stevendeo marked this pull request as draft November 26, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant