>fitting 4 engines
Changing the number of engines would most likely require a total redesign of the wing.
At least two of the planes you list are not being phased out because they were quads. The A340-300 was doing very well against the 777, however the A340-600 did very poorly against the 777-300ER. This is because the frame was too long and narrow, requiring extra reinforcement not to bend, thus ending up much heavier than the frame of the 777. The frame itself was grossly overweight, the extra engines were a rounding error.
The A380 was (and still is) extremely efficient (in terms of fuel burn per seat, at equivalent seating density), with a fuel consumption similar if not better than that of 787s or A350s, despite engines one generation older. It is, however, way way too big. In the end flying empty seats is very inefficient. But that has little to do with having 4 engines instead of 2.
The re-engined 777-9 will certainly be the most efficient plane flying when it is launched in 2021. Yet sales are lacking. It may, like the A380, turned out to be too big.
[1] https://leehamnews.com/2015/12/11/bjorns-corner-twins-or-qua...
So, de facto, each engine is strictly required, and having twice as many as a twin, quad jets are half as reliable as a twin, all other things being equal.
(me: licensed dispatcher who worked with the BAE-146 for a time. Incidentally, "BAe" stands for "Bring Another Engine" <grin>.)