summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2018-07-19 01:46:21 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2018-07-19 01:46:21 +0000
commitd41faecc4969a3c707f98a9925f6c88e895f9bde (patch)
treecebcafe57c0f57e8f9a300c746dbdb9be6fc0222 /llvm/test
parent6b87e0c18f049172b33144f561cf4baa8b225d8d (diff)
downloadbcm5719-llvm-d41faecc4969a3c707f98a9925f6c88e895f9bde.tar.gz
bcm5719-llvm-d41faecc4969a3c707f98a9925f6c88e895f9bde.zip
[SCEV] Fix buggy behavior in getAddExpr with truncs
SCEV tries to constant-fold arguments of trunc operands in SCEVAddExpr, and when it does that, it passes wrong flags into the recursion. It is only valid to pass flags that are proved for narrow type into a computation in wider type if we can prove that trunc instruction doesn't actually change the value. If it did lose some meaningful bits, we may end up proving wrong no-wrap flags for sum of arguments of trunc. In the provided test we end up with `nuw` where it shouldn't be because of this bug. The solution is to conservatively pass `SCEV::FlagAnyWrap` which is always a valid thing to do. Reviewed By: sanjoy Differential Revision: https://reviews.llvm.org/D49471 llvm-svn: 337435
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Analysis/ScalarEvolution/truncate.ll34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/test/Analysis/ScalarEvolution/truncate.ll b/llvm/test/Analysis/ScalarEvolution/truncate.ll
index 878f7b3b31b..7ae6908fc20 100644
--- a/llvm/test/Analysis/ScalarEvolution/truncate.ll
+++ b/llvm/test/Analysis/ScalarEvolution/truncate.ll
@@ -73,3 +73,37 @@ bb34: ; preds = %bb25
%tmp36 = icmp ugt i32 %tmp16, 52
br i1 %tmp36, label %bb3, label %bb13
}
+
+; Make sure that no nuw flag is assigned to %tmp27, otherwise we will have a
+; poisoned value.
+define void @no_nuw(i64 %param) {
+
+; CHECK-LABEL: Classifying expressions for: @no_nuw
+; CHECK: %tmp27 = add i64 %tmp20, -1
+; CHECK-NOT: (-1 + %tmp20)<nuw>
+; CHECK-NEXT: --> (-1 + %tmp20) U:
+
+bb:
+ %shift = shl i64 %param, 58
+ br label %bb18
+
+bb18: ; preds = %bb36, %bb
+ %tmp20 = phi i64 [ %shift, %bb ], [ 0, %bb36 ]
+ %tmp21 = phi i64 [ 0, %bb ], [ %tmp24, %bb36 ]
+ %tmp22 = phi i32 [ -6, %bb ], [ %tmp46, %bb36 ]
+ %tmp25 = add i32 %tmp22, 1
+ %tmp26 = sext i32 %tmp25 to i64
+ %tmp27 = add i64 %tmp20, -1
+ %tmp28 = mul i64 %tmp27, %tmp26
+ %tmp29 = icmp ult i64 %tmp21, 1048576
+ br i1 %tmp29, label %bb36, label %bb30
+
+bb30: ; preds = %bb18
+ ret void
+
+bb36: ; preds = %bb18
+ %tmp24 = add nuw i64 %tmp21, 1
+ %tmp45 = trunc i64 %tmp28 to i32
+ %tmp46 = sub i32 %tmp22, %tmp45
+ br label %bb18
+}
OpenPOWER on IntegriCloud