I would definitely not recommend visiting all three places. You only have eight days. Barcelona and Madrid are large cities with many interesting sights. I could easily fill all your time in Barcelona alone. For Madrid, I'd need to add some side-trips, but it has magnificent ones (Toledo, Segovia and Cuenca just for starters). Ibiza would require flights to and from, and any time you insert airports into the mix, you are going to lose more than half a day in transit. On a short trip like yours, you really can't afford to lose the time needed to fly to Ibiza.
I can't get a sense of your age from your brief post, so I feel I should warn you that Ibiza has the reputation of being a party island.
To figure out how to split your time, you need to get a guidebook and read about the sightseeing opportunities in Barcelona and Madrid.
At a very, very high level, Madrid is great for art lovers (three major museums) and folks interested in fabulous side-trips (can be just one day) to places like Toledo, Segovia, Cuenca. It has an ornate royal palace and a variety of other museums. The oldest buildings are 17th century and very handsome.
Barcelona is great for lovers of funky modernista architecture. It's older and has medieval neighborhoods to wander around in. It has many art museums, but it doesn't have the Prado. There are good side-trips to the charming Girona, Montserrat and Dali sights in Figueres and just outside Cadaques. Barcelona has beaches that are easily reached. I can't comment on whether late May/early June will be swimming weather.
I'm not doing either city justice, I know. But I hope you can see that they are quite different. Even should you decide to split your time between them, you'll need to decide how to divide that time.