Loop Strength Reduction and lost "nsw" flag


I was looking a bit at the handling of "nsw" flags, and found one case I am not sure what to do about. Function @f4 in test/CodeGen/SystemZ/loop-01.ll contains an add instruction which decrements the IV with 1. This result is then compared to against zero in the loop latch, but it also has another user.

I find that if i add "nsw" on that add instruction (as done in attachement), LSR will create an identical instruction without the flag for the other (non-IV) user. The problem is then that during isel, the "nsw" flag is lost - it seems that only one add node without it is created.

Any ideas how this could be fixed?



bin/llc -mtriple=s390x-linux-gnu -mcpu=z14 f4.ll

cat f4.ll

f4.ll (962 Bytes)