In principle, there are two effects of merging companies that have opposite effects on welfare/efficiency:
A) A merger could result in more efficient production. This could be because the merged firm will adopt the practices of the most productive of the two original firms. Alternatively, it could be because of economies of scale. We think that many processes are more efficient if they are done on a bigger scale. The investment in designing a product and designing and installing a very efficient production process only pays off if you have a large enough scale. finally, it could even happen because it's efficient for a single entity to own the upstream and downstream processes in order to avoid negotiation costs and invest heavily in relationship-specific technology.
B) On the other hand, a merger could result in less competition. This could happen because the two companies were competing against each other and they are no longer doing so after the merger. It could also happen because the new larger firm is going to be a dominant player in input and output markets. It will be able to dictate terms to its suppliers, and also to its consumers, and even to its specialized employees.
The presence of these effects means that the work of anti-trust regulators is complex. They have to evaluate the likelihood on one of the effects being bigger than the other before the merger takes place in order to allow it or block it. Often what they do is to impose conditions on the merged entity in a way that guarantees that it will not be a dominant player.