C++: Work around poor codegen for forex in IR-based range analysis#13035
C++: Work around poor codegen for forex in IR-based range analysis#13035rdmarsh2 merged 1 commit intogithub:mainfrom
forex in IR-based range analysis#13035Conversation
…RangeAnalysisStage.qll'.
|
It's really sad that we have to use hacks like this. @jbj |
| rank[r](SemSsaReadPositionPhiInputEdge e | | ||
| e.phiInput(phi, _) | ||
| | | ||
| e order by e.getOrigBlock().getUniqueId() |
There was a problem hiding this comment.
How unique are these ids? From what I can tell, this call ultimately leads to the database id of block.getFirstInstruction().getAst(). Can it never happen that an AST element produces two different instructions that are both first in a basic block?
There was a problem hiding this comment.
Indeed, the result of e.getOrigBlock().getUniqueId() is the database id of e's IRBlock's getFirstInstruction().getAst(). I can't quite think of an AST element with that property, but I'm sure one can construct something like this (maybe something involving the ternary operator?).
Originally, we were using the display index from the basic block, but this was totally infeasible to compute on real projects. If you have any suggestions for an integer representation whose uniqueness is easier to argue I'm all for it 😄.
This scheme has been used for a while now already in the new range-analysis library (in the modulus-phase) without any observable issues, though.
There was a problem hiding this comment.
It should be easy to check with a consistency query whether two IRBlocks ever get the same id. And even if they do, I suppose it only matters here if those IRBlocks go into the same phi node.
|
DCA looks fantastic 🤩. |
|
LGTM modulo @jbj's comment about uniqueness. I don't think we're making the situation worse here, but I'd like to see a consistency query for that in a followup PR. |
Recursion through
forallandforexneeds special care in QL. During the modulus-analysis phase of the IR-based range analysis such care is already taken, but the same level of care wasn't taken in the main range analysis module. This resulted in horrible antijoins on some projects. Here is one such example:(I cancelled the evaluation midway)
This PR moves the modulus-analysis tricks to the
Utilsfile, and uses it in the main range analysis module. This results in a much better pipeline:The "trick" is to replace code such as:
with