diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4950,6 +4950,8 @@ case Instruction::Mul: case Instruction::Shl: case Instruction::GetElementPtr: + case Instruction::And: + case Instruction::Or: // These operations all propagate poison unconditionally. Note that poison // is not any particular value, so xor or subtraction of poison with // itself still yields poison, not zero. diff --git a/llvm/test/Analysis/ScalarEvolution/nsw.ll b/llvm/test/Analysis/ScalarEvolution/nsw.ll --- a/llvm/test/Analysis/ScalarEvolution/nsw.ll +++ b/llvm/test/Analysis/ScalarEvolution/nsw.ll @@ -223,8 +223,26 @@ ret void } -define void @bad_postinc_nsw_b(i32 %n) { -; CHECK-LABEL: Classifying expressions for: @bad_postinc_nsw_b +define void @bad_postinc_nsw_b_or(i32 %n) { +; CHECK-LABEL: Classifying expressions for: @bad_postinc_nsw_b_or +entry: + br label %loop + +loop: + %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ] + %iv.inc = add nsw i32 %iv, 7 + %iv.inc.and = or i32 %iv.inc, 0 +; CHECK: %iv.inc = add nsw i32 %iv, 7 +; CHECK-NEXT: --> {7,+,7}<%loop> + %becond = icmp ult i32 %iv.inc.and, %n + br i1 %becond, label %loop, label %leave + +leave: + ret void +} + +define void @bad_postinc_nsw_b_and(i32 %n) { +; CHECK-LABEL: Classifying expressions for: @bad_postinc_nsw_b_and entry: br label %loop @@ -233,7 +251,7 @@ %iv.inc = add nsw i32 %iv, 7 %iv.inc.and = and i32 %iv.inc, 0 ; CHECK: %iv.inc = add nsw i32 %iv, 7 -; CHECK-NEXT: --> {7,+,7}<%loop> +; CHECK-NEXT: --> {7,+,7}<%loop> %becond = icmp ult i32 %iv.inc.and, %n br i1 %becond, label %loop, label %leave