[NFC][SCEV] Some tests for shifts by bitwidth-2/bitwidth-1 w/ no-wrap flags
authorRoman Lebedev <lebedev.ri@gmail.com>
Fri, 5 Jun 2020 08:23:16 +0000 (11:23 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 5 Jun 2020 08:45:09 +0000 (11:45 +0300)
llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll

index caf372f..2b60192 100644 (file)
@@ -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}<nsw><%loop>
+  %index32 = shl nsw i32 %i, 30
+
+; CHECK: %index64 =
+; CHECK: --> {(sext i32 (1073741824 * %start) to i64),+,1073741824}<nsw><%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