-- | Conditional branch
genCondBranch :: CmmExpr -> BlockId -> BlockId -> Maybe Bool -> LlvmM StmtData
genCondBranch cond idT idF likely = do
    let labelT = blockIdToLlvm idT
    let labelF = blockIdToLlvm idF
    -- See Note [Literals and branch conditions].
    (vc, stmts1, top1) <- exprToVarOpt i1Option cond
    if getVarType vc == i1
        then do
            (vc', (stmts2, top2)) <- case likely of
              Just b -> genExpectLit (if b then 1 else 0) i1  vc
              _      -> pure (vc, (nilOL, []))
            let s1 = BranchIf vc' labelT labelF
            return (stmts1 `appOL` stmts2 `snocOL` s1, top1 ++ top2)
        else do
            dflags <- getDynFlags
            panic $ "genCondBranch: Cond expr not bool! (" ++ showSDoc dflags (ppr vc) ++ ")"


-- | Generate call to llvm.expect.x intrinsic. Assigning result to a new var.
genCondBranch :: CmmExpr -> BlockId -> BlockId -> Maybe Bool -> LlvmM StmtData
genCondBranch cond idT idF likely = do
    let labelT = blockIdToLlvm idT
    let labelF = blockIdToLlvm idF
    -- See Note [Literals and branch conditions].
    (vc, stmts1, top1) <- exprToVarOpt i1Option cond
    if getVarType vc == i1
        then do
            (vc', (stmts2, top2)) <- case likely of
              Just b -> genExpectLit (if b then 1 else 0) i1  vc
              _      -> pure (vc, (nilOL, []))
            let s1 = BranchIf vc' labelT labelF
            return (stmts1 `appOL` stmts2 `snocOL` s1, top1 ++ top2)
        else do
            dflags <- getDynFlags
            panic $ "genCondBranch: Cond expr not bool! (" ++ showSDoc dflags (ppr vc) ++ ")"


-- | Generate call to llvm.expect.x intrinsic. Assigning result to a new var.
genCondBranch cond idT idF likely = do
    let labelT = blockIdToLlvm idT
    let labelF = blockIdToLlvm idF
    -- See Note [Literals and branch conditions].
    (vc, stmts1, top1) <- exprToVarOpt i1Option cond
    if getVarType vc == i1
        then do
            (vc', (stmts2, top2)) <- case likely of
              Just b -> genExpectLit (if b then 1 else 0) i1  vc
              _      -> pure (vc, (nilOL, []))
            let s1 = BranchIf vc' labelT labelF
            return (stmts1 `appOL` stmts2 `snocOL` s1, top1 ++ top2)
        else do
            dflags <- getDynFlags
            panic $ "genCondBranch: Cond expr not bool! (" ++ showSDoc dflags (ppr vc) ++ ")"


-- | Generate call to llvm.expect.x intrinsic. Assigning result to a new var.