[clang] [KeyInstr][Clang] For range stmt atoms (PR #134647)

Stephen Tozer via cfe-commits cfe-commits at lists.llvm.org
Tue May 27 03:44:27 PDT 2025


================
@@ -1448,7 +1448,14 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
   if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
     BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
         BoolCondVal, Stmt::getLikelihood(S.getBody()));
-  Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
+  auto *I = Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
+  // Key Instructions: Emit the condition and branch as separate atoms to
+  // match existing loop stepping behaviour. FIXME: We could have the branch as
+  // the backup location for the condition, which would probably be a better
+  // experience.
+  if (auto *I = dyn_cast<llvm::Instruction>(BoolCondVal))
+    addInstToNewSourceAtom(I, nullptr);
----------------
SLTozer wrote:

Not a big fan of the shadowing here, it seems like it'd make things harder to parse at a glance?

https://github.com/llvm/llvm-project/pull/134647


More information about the cfe-commits mailing list