genCall (PrimTarget (MO_AtomicWrite _width)) [] [addr, val] = runStmtsDecls $ do
    addrVar <- exprToVarW addr
    valVar <- exprToVarW val
    let ptrTy = pLift $ getVarType valVar
        ptrExpr = Cast LM_Inttoptr addrVar ptrTy
    ptrVar <- doExprW ptrTy ptrExpr
    statement $ Expr $ AtomicRMW LAO_Xchg ptrVar valVar SyncSeqCst

-- Handle memcpy function specifically since llvm's intrinsic version takes
-- some extra parameters.
genCall (PrimTarget (MO_AtomicWrite _width)) [] [addr, val] = runStmtsDecls $ do
    addrVar <- exprToVarW addr
    valVar <- exprToVarW val
    let ptrTy = pLift $ getVarType valVar
        ptrExpr = Cast LM_Inttoptr addrVar ptrTy
    ptrVar <- doExprW ptrTy ptrExpr
    statement $ Expr $ AtomicRMW LAO_Xchg ptrVar valVar SyncSeqCst

-- Handle memcpy function specifically since llvm's intrinsic version takes
-- some extra parameters.
genCall (PrimTarget (MO_AtomicWrite _width)) [] [addr, val] = runStmtsDecls $ do
    addrVar <- exprToVarW addr
    valVar <- exprToVarW val
    let ptrTy = pLift $ getVarType valVar
        ptrExpr = Cast LM_Inttoptr addrVar ptrTy
    ptrVar <- doExprW ptrTy ptrExpr
    statement $ Expr $ AtomicRMW LAO_Xchg ptrVar valVar SyncSeqCst

-- Handle memcpy function specifically since llvm's intrinsic version takes
-- some extra parameters.