The following unit test shows incorrect behavior regarding undef inputs: $ opt -correlated-propagation -cvp-dont-add-nowrap-flags=false Transforms/CorrelatedValuePropagation/sub.ll The issue is the branch on undef, which if we assume is a non-deterministic jump, leads to branch %then, which then does a 'sub nuw' on an undef (which is poison). Possible solutions: same as in #42617. define i32 @test11(* %p, i32 %i) { %limit = load i32, * %p, align 4 %range_l#0%limit = icmp sge i32 %limit, 0 %range_h#0%limit = icmp slt i32 %limit, 2147483647 %range#0%limit = and i1 %range_l#0%limit, %range_h#0%limit assume_non_poison i1 %range#0%limit %within.1 = icmp slt i32 %limit, %i %i.minus.7 = add i32 %i, 4294967289 %within.2 = icmp slt i32 %limit, %i.minus.7 %within = and i1 %within.1, %within.2 br i1 %within, label %then, label %else %then: %i.minus.6 = sub i32 %i, 6 ret i32 %i.minus.6 %else: ret i32 0 } => define i32 @test11(* %p, i32 %i) { %limit = load i32, * %p, align 4 %range_l#0%limit = icmp sge i32 %limit, 0 %range_h#0%limit = icmp slt i32 %limit, 2147483647 %range#0%limit = and i1 %range_l#0%limit, %range_h#0%limit assume_non_poison i1 %range#0%limit %within.1 = icmp slt i32 %limit, %i %i.minus.7 = add i32 %i, 4294967289 %within.2 = icmp slt i32 %limit, %i.minus.7 %within = and i1 %within.1, %within.2 br i1 %within, label %then, label %else %then: %i.minus.6 = sub nsw nuw i32 %i, 6 ret i32 %i.minus.6 %else: ret i32 0 } Transformation doesn't verify! ERROR: Target is more poisonous than source Example: * %p = #x2dc920000000 i32 %i = undef Source: i32 %limit = #x00000000 (0) i1 %range_l#0%limit = #x1 (1) i1 %range_h#0%limit = #x1 (1) i1 %range#0%limit = #x1 (1) i1 %within.1 = undef i32 %i.minus.7 = undef i1 %within.2 = undef i1 %within = undef i32 %i.minus.6 = undef Target: i32 %limit = #x00000000 (0) i1 %range_l#0%limit = #x1 (1) i1 %range_h#0%limit = #x1 (1) i1 %range#0%limit = #x1 (1) i1 %within.1 = undef i32 %i.minus.7 = undef i1 %within.2 = undef i1 %within = undef i32 %i.minus.6 = poison Source value: undef Target value: poison
We now have langref stating that jump on undef is UB. So this one is good.