Since SystemZ supports counting of leading zeros with the FLOGR instruction, it seems isCheapToSpeculateCtlz() should return true.
The effect on spec by doing this is a few less branches but also a few more other instructions which I have not looked into in detail.
So far I have assumed that speculation is better than a branch also in the cases that requires extension and subtraction (i8 and i16).
I also discovered that even with this in place (which stops CodeGenPrepare from emitting the ctlz_zero_undef (instructions), these nodes appear in benchmarks. I therefore also added isel handling for them, just as for ctlz nodes. This improved some cases it seems that previously got expanded into huge sequences instead of using flogr.
The new tests can be run and the effects of the patch are demonstrated by them. I also saw an issue with unfolded adds of immediates (see FIXME note in test file).