[llvm-branch-commits] [clang] [KeyInstr][Clang] Do stmt atom (PR #134644)

Jeremy Morse via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu May 22 16:31:24 PDT 2025


================
@@ -1242,9 +1242,17 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
   // As long as the condition is true, iterate the loop.
   if (EmitBoolCondBranch) {
     uint64_t BackedgeCount = getProfileCount(S.getBody()) - ParentCount;
-    Builder.CreateCondBr(
+    auto *I = Builder.CreateCondBr(
         BoolCondVal, LoopBody, LoopExit.getBlock(),
         createProfileWeightsForLoop(S.getCond(), BackedgeCount));
+
+    // 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 (no jumping to the brace).
+    if (auto *I = dyn_cast<llvm::Instruction>(BoolCondVal))
+      addInstToNewSourceAtom(I, nullptr);
----------------
jmorse wrote:

Please call the casted BoolCondVal something other than `I` to avoid the reader having to think about shadowed variables ._.

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


More information about the llvm-branch-commits mailing list