Skip to content

Conversation

@resistor
Copy link
Collaborator

  • [CodeGen] Don't create combine loops for PTRADD with opaque constants
  • Add test for infinite combine fix in the previous commit
  • [CodeGen] Use index type for pointer offset in replaceStoreOfInsertLoad
  • [AST][Sema] Support unsigned __intcap in getCorrespondingSignedType
  • Fix clangd unit test regression.

jrtc27 and others added 5 commits November 13, 2025 21:58
We were implicitly assuming here that, if one of Y or Z is a constant,
either the other is not or we will have already (in the nested PTRADD
case) constant-folded both of them into one, and thus don't need to
consider the possibility. However, opaque constants exist and do not get
constant-folded, so we can end up cycling between PTRADD+ADD and
PTRADD+PTRADD. Catch this case by checking the other is not a constant
and skipping all but one combine if so.

No test is provided since I've yet to be able to trigger it in CHERI
LLVM, only downstream in Codasip LLVM and Morello LLVM (and only when
targeting CHERI-RISC-V even in Morello LLVM), both of which enable SCEV
and thus do interesting loop transformations.

Fixes: 05fd67a ("[CodeGen][CHERI-Generic] Support commuting capability offsets when safe")
This was somewhat awkward to reduce since giving the --print-before-all
IR to llc would optimize away the pattern that triggers the loop.
Writing the test with -start-before=riscv-isel allowed me to reduce it
with bugpoint and then manually remove all branches to get the minimal
test from this comit
Also use getMemBasePlusOffset rather than a raw ADD since that won't
work for capability types either.

Fixes: 38e1851 ("[DAGCombine] Fold (store (insert_elt (load p)) x p) -> (store x)")
This is used by the new __make_signed(T) builtin. Note (signed) __intcap
is already handled by getCorrespondingUnsignedSignedType from many years
ago.

Fixes: 1a54ef1 ("[clang] adds unary type transformations as compiler built-ins")
@resistor resistor merged commit 601094a into CHERIoT-Platform:cheriot Nov 14, 2025
8 checks passed
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.

3 participants