Any whip can be 'u'sed (both from the backpack and in the tool slot) to get a prompt to engage in self-flagellation. If you choose 'y'es, the PC will receive some damage (based on the whip used and the PC's PV) and some positive alignment shift. The shift seems to be 10xdamage, which means the PC needs to inflict ~20 damage to equal the alignment gain of casting one healing spell on a pet or monster (the latter only counts if the PC has not attacked it in any way).
Practical uses Edit
In the late game, donating money or healing monsters (drowning a pet in Water Dragon Cave is an easy way to produce a target for healing spells) are often more efficient means of gaining alignment. However, self-flagellation can be used in the early game if alignment change needs to be manufactured. Putting on some armor with negative PV or using better whips certainly improves the effectiveness of this method.
If you are involved in grindy activities in safe areas (farming herbs in a pacified Big Room, mining in the Ogre Cave), you might want to use self-flagellation, as it provides an opportunity to train the Healing skill, while also manipulating alignment.
If the PC whips himself to death while wearing an amulet of life saving, the alignment boost is rather significant, but still only amounts to ~10 healing casts on a pet. In most games AoLS has better uses. Note that self-flagellation is only fatal if employed at 1 HP; if the PC is at a higher HP total they are safe, regardless of their PV and the whip used (aside from whip of the snake).