Microsoft will lay off nearly 4% of its workforce, the company said on Wednesday, in the latest job cuts as the tech giant looks to rein in costs amid hefty investments in artificial intelligence infrastructure.