@@ -431,7 +431,9 @@ class YkIRWriter {
431431 serialiseOperand (I, VLMap, I->getOperand (OI));
432432 }
433433
434- VLMap[I] = {BBIdx, InstIdx};
434+ if (!I->getType ()->isVoidTy ()) {
435+ VLMap[I] = {BBIdx, InstIdx};
436+ }
435437 InstIdx++;
436438 }
437439
@@ -447,14 +449,28 @@ class YkIRWriter {
447449 // num_operands:
448450 // We don't serialise any operands, because traces will guide us.
449451 OutStreamer.emitInt32 (0 );
450-
451- VLMap[I] = {BBIdx, InstIdx};
452- InstIdx++;
453452 } else {
453+ // type_index:
454+ OutStreamer.emitSizeT (typeIndex (I->getType ()));
455+ // opcode:
456+ serialiseOpcode (OpCode::CondBr);
454457 // We DO need operands for conditional branches, so that we can build
455458 // guards.
456- serialiseInstGeneric (I, VLMap, BBIdx, InstIdx, OpCode::CondBr);
459+ //
460+ // Note that in LLVM IR, the operands are ordered (despite the order they
461+ // appear in the language reference): cond, if-false, if-true. We
462+ // re-order those during lowering to avoid confusion.
463+ //
464+ // num_operands:
465+ OutStreamer.emitInt32 (3 );
466+ // OPERAND 0: condition.
467+ serialiseOperand (I, VLMap, I->getOperand (0 ));
468+ // OPERAND 1: block to go to if true.
469+ serialiseOperand (I, VLMap, I->getOperand (2 ));
470+ // OPERAND 2: block to go to if false.
471+ serialiseOperand (I, VLMap, I->getOperand (1 ));
457472 }
473+ InstIdx++;
458474 }
459475
460476 void serialiseGetElementPtr (GetElementPtrInst *I, ValueLoweringMap &VLMap,
0 commit comments