Created attachment 11329 [details] Unit test SCEV::createNodeForPhi flags an AddRec expression as NSW if the value on the backedge is flagged nsw. It disregards whether the value has the same form as the expression, or is merely a subexression as in: %i.0 = phi i32 [ 0, %pre ], [ %tmp3, %loop ] %tmp2 = add i32 %i.0, 1 %tmp3 = add nsw i32 %tmp2, 1 %check = icmp slt i32 %i.0, %N A unit test is attached. It could be appended to nsw.ll. I believe it would be sufficient to test if one of the BEValue's operands is the PHINode before propagating NSW without losing any important cases.