[llvm] [ConstantTime][LLVM] Add llvm.ct.select intrinsic with generic SelectionDAG lowering (PR #166702)
Marvin Häuser via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 12 03:02:56 PST 2026
mhaeuser wrote:
@statham-arm I started a discussion about “contagious markers” (i.e., such that propagate if at least one member has the marker) to automatically classify secret types. I was then asked why I don’t use a regular automatic marker (such that propagate when all members have the marker) for non-secret. Maybe you should be careful what you wish for. ;)
@kumarak Thanks again for the detailed feedback! My main concern really is the optimization part.
> The intrinsic approach doesn’t broadly disable optimizations. Most of the optimizer continues to run unchanged, and we only restrict the specific rewrites that would break constant-time guarantees.
If that means what I understood it does, that addresses my concern and I need to go back to studying both LLVM and the PR. However, I’m not yet sure it does. One arbitrary example I might misinterpret: `visitSELECT()`, the `DAGCombiner` for non-ct select, calls `foldBoolSelectToLogic()`, which may fold `select` into (non-short-circuiting) boolean logic. From what I can tell, this is perfectly ct-safe. `visitConstantTimeSelect()` (the ct counterpart, which at the very least is a restricted duplicate of the non-ct optimization policy) on the other hand does not apply this. I suspect this is not done because the boolean instructions cannot be marked secret and we are not yet at the expansion point? Would a ct-compliant variant under this intrinsic model not require a duplication (or abstraction) of the optimization to use secret boolean intrinsics? Wouldn’t this apply to most optimizations that for any reason substitute opcodes?
DIT/DOIT is an “extra” for me and I don’t think it matters all that much. However:
> The intrinsic/pseudo-instruction approach helps here because secrecy is carried by the opcode itself and preserved until the dedicated expansion point.
“Expansion point” is exactly my point here. I know that there at least is some instruction relaxation going on in the x86 backend after said expansion point. I suppose it is not too hard to argue that these relaxations are safe with the opcode tables. However, I am not sure there wasn’t more that could theoretically harm DIT/DOIT-compatible selection.
(For all intents and purposes, please consider this a theoretical discussion that shouldn’t affect this specific PR, but either future work or my misconceptions of what is going on here. :) )
https://github.com/llvm/llvm-project/pull/166702
More information about the llvm-commits
mailing list