diff --git a/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll b/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll index caf372f9ea91bc..2b60192b1fb2d2 100644 --- a/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll +++ b/llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll @@ -525,6 +525,106 @@ exit: ret void } +; Example where a shl should get the nuw flag +define void @test-shl-nuw-edgecase(float* %input, i32 %start, i32 %numIterations) { +; CHECK-LABEL: @test-shl-nuw-edgecase +entry: + br label %loop +loop: + %i = phi i32 [ %nexti, %loop ], [ %start, %entry ] + +; CHECK: %index32 = +; CHECK: --> {(-2147483648 * %start),+,-2147483648}<%loop> + %index32 = shl nuw i32 %i, 31 + +; CHECK: %index64 = +; CHECK: --> (sext i32 {(-2147483648 * %start),+,-2147483648}<%loop> + %index64 = sext i32 %index32 to i64 + + %ptr = getelementptr inbounds float, float* %input, i64 %index64 + %nexti = add nsw i32 %i, 1 + %f = load float, float* %ptr, align 4 + %exitcond = icmp eq i32 %nexti, %numIterations + br i1 %exitcond, label %exit, label %loop +exit: + ret void +} + +; Example where a shl should get the nuw flag +define void @test-shl-nuw-nsw(float* %input, i32 %start, i32 %numIterations) { +; CHECK-LABEL: @test-shl-nuw-nsw +entry: + br label %loop +loop: + %i = phi i32 [ %nexti, %loop ], [ %start, %entry ] + +; CHECK: %index32 = +; CHECK: --> {(-2147483648 * %start),+,-2147483648}<%loop> + %index32 = shl nuw nsw i32 %i, 31 + +; CHECK: %index64 = +; CHECK: --> (sext i32 {(-2147483648 * %start),+,-2147483648}<%loop> + %index64 = sext i32 %index32 to i64 + + %ptr = getelementptr inbounds float, float* %input, i64 %index64 + %nexti = add nsw i32 %i, 1 + %f = load float, float* %ptr, align 4 + %exitcond = icmp eq i32 %nexti, %numIterations + br i1 %exitcond, label %exit, label %loop +exit: + ret void +} + +; Example where a shl should not get the nsw flag +define void @test-shl-no-nsw(float* %input, i32 %start, i32 %numIterations) { +; CHECK-LABEL: @test-shl-no-nsw +entry: + br label %loop +loop: + %i = phi i32 [ %nexti, %loop ], [ %start, %entry ] + +; CHECK: %index32 = +; CHECK: --> {(-2147483648 * %start),+,-2147483648}<%loop> + %index32 = shl nsw i32 %i, 31 + +; CHECK: %index64 = +; CHECK: --> (sext i32 {(-2147483648 * %start),+,-2147483648}<%loop> + %index64 = sext i32 %index32 to i64 + + %ptr = getelementptr inbounds float, float* %input, i64 %index64 + %nexti = add nsw i32 %i, 1 + %f = load float, float* %ptr, align 4 + %exitcond = icmp eq i32 %nexti, %numIterations + br i1 %exitcond, label %exit, label %loop +exit: + ret void +} + +; Example where a shl should get the nsw flag. +define void @test-shl-nsw-edgecase(float* %input, i32 %start, i32 %numIterations) { +; CHECK-LABEL: @test-shl-nsw-edgecase +entry: + br label %loop +loop: + %i = phi i32 [ %nexti, %loop ], [ %start, %entry ] + +; CHECK: %index32 = +; CHECK: --> {(1073741824 * %start),+,1073741824}<%loop> + %index32 = shl nsw i32 %i, 30 + +; CHECK: %index64 = +; CHECK: --> {(sext i32 (1073741824 * %start) to i64),+,1073741824}<%loop> + %index64 = sext i32 %index32 to i64 + + %ptr = getelementptr inbounds float, float* %input, i64 %index64 + %nexti = add nsw i32 %i, 1 + %f = load float, float* %ptr, align 4 + %exitcond = icmp eq i32 %nexti, %numIterations + br i1 %exitcond, label %exit, label %loop +exit: + ret void +} + ; Example where a shl should get the nuw flag. define void @test-shl-nuw(float* %input, i32 %numIterations) { ; CHECK-LABEL: @test-shl-nuw