Can a 3-axis magnetometer be tilt compensated when moving/accelerating?
Somehow, I didn't notice this question at the time it was asked, or I would have answered sooner.

Yes, what you want to do is definitely possible, and there is software out there to help you do it, but unfortunately, some of it is quite expensive.

Basically, you need to use something like a Kalman filter to combine all of your data (raw acceleration, angular rate and magnetic field readings) into a complete model of the sensor that includes both its relative position and its absolute attitude (orientation). (If you also add something like a GPS receiver, you can also get absolute position.)

The filter operates in such a way that it uses the magnetometer to correct for the long-term errors (e.g., offset and scale changes) in the accelerometers and gyros, and then you can use this estimate of the attitude of the sensor to tilt-compensate the magnetic field readings in order to get a magnetic heading. As a bonus, you also get the true "course over ground" of the sensor from the sequence of position estimates, which could differ from the heading if the swimmer is swimming in a cross-current of some sort.

As far as the software for doing this kind of post-processing, one example I'm aware of is called Inertial Explorer, but it's very expensive and is probably way overkill for your application. If you search around, you should be able to find open-source projects that meet your needs.