llvm.org GIT mirror llvm / a19127b
[SCEV] Do not insert if it is already in cache This is fix for the crash caused by ScalarEvolution::getTruncateExpr. It expects that if it checked the condition that SCEV is not in UniqueSCEVs cache in the beginning that it will not be there inside this method. However during recursion and transformation/simplification for sub expression, it is possible that these modifications will end up with the same SCEV as we started from. So we must always check whether SCEV is in cache and do not insert item if it is already there. Reviewers: sanjoy, mkazantsev, craig.topper Reviewed By: sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41380 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321472 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 2 years ago
2 changed file(s) with 82 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
12671267 }
12681268 if (!hasTrunc)
12691269 return getAddExpr(Operands);
1270 UniqueSCEVs.FindNodeOrInsertPos(ID, IP); // Mutates IP, returns NULL.
1270 // In spite we checked in the beginning that ID is not in the cache,
1271 // it is possible that during recursion and different modification
1272 // ID came to cache, so if we found it, just return it.
1273 if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
1274 return S;
12711275 }
12721276
12731277 // trunc(x1*x2*...*xN) --> trunc(x1)*trunc(x2)*...*trunc(xN) if we can
12831287 }
12841288 if (!hasTrunc)
12851289 return getMulExpr(Operands);
1286 UniqueSCEVs.FindNodeOrInsertPos(ID, IP); // Mutates IP, returns NULL.
1290 // In spite we checked in the beginning that ID is not in the cache,
1291 // it is possible that during recursion and different modification
1292 // ID came to cache, so if we found it, just return it.
1293 if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
1294 return S;
12871295 }
12881296
12891297 // If the input value is a chrec scev, truncate the chrec's operands.
0 ; RUN: opt < %s -analyze -scalar-evolution
1 ; RUN: opt < %s -passes='print'
2 ; Regression test for assert ScalarEvolution::getTruncateExpr.
3
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
5 target triple = "x86_64-unknown-linux-gnu"
6
7 define void @snork(i8* %arg, i8 %arg1, i64 %arg2) {
8 bb:
9 br label %bb12
10
11 bb3: ; preds = %bb34
12 br i1 true, label %bb4, label %bb12
13
14 bb4: ; preds = %bb3
15 br label %bb6
16
17 bb5: ; preds = %bb6
18 ret void
19
20 bb6: ; preds = %bb6, %bb4
21 %tmp = phi i64 [ %tmp28, %bb4 ], [ %tmp10, %bb6 ]
22 %tmp7 = phi i32 [ 3, %bb4 ], [ %tmp11, %bb6 ]
23 %tmp8 = trunc i64 %tmp to i32
24 %tmp9 = sdiv i32 %tmp8, %tmp7
25 %tmp10 = add i64 %tmp, -1
26 %tmp11 = add i32 %tmp9, %tmp7
27 br i1 true, label %bb5, label %bb6
28
29 bb12: ; preds = %bb3, %bb
30 br label %bb13
31
32 bb13: ; preds = %bb34, %bb12
33 %tmp14 = phi i64 [ %arg2, %bb12 ], [ %tmp28, %bb34 ]
34 %tmp15 = phi i8 [ %arg1, %bb12 ], [ %tmp26, %bb34 ]
35 %tmp16 = phi i32 [ 1, %bb12 ], [ %tmp35, %bb34 ]
36 %tmp17 = add i8 %tmp15, -1
37 %tmp18 = sext i8 %tmp17 to i64
38 %tmp19 = sub i64 1, %tmp14
39 %tmp20 = add i64 %tmp19, %tmp18
40 %tmp21 = trunc i64 %tmp20 to i32
41 %tmp22 = icmp eq i32 %tmp21, 0
42 br i1 %tmp22, label %bb32, label %bb23
43
44 bb23: ; preds = %bb13
45 br i1 true, label %bb25, label %bb24
46
47 bb24: ; preds = %bb23
48 br label %bb25
49
50 bb25: ; preds = %bb24, %bb23
51 %tmp26 = add i8 %tmp15, -2
52 %tmp27 = sext i8 %tmp26 to i64
53 %tmp28 = sub i64 %tmp27, %tmp20
54 %tmp29 = trunc i64 %tmp28 to i32
55 %tmp30 = icmp eq i32 %tmp29, 0
56 br i1 %tmp30, label %bb31, label %bb34
57
58 bb31: ; preds = %bb25
59 br label %bb33
60
61 bb32: ; preds = %bb13
62 br label %bb33
63
64 bb33: ; preds = %bb32, %bb31
65 unreachable
66
67 bb34: ; preds = %bb25
68 %tmp35 = add nuw nsw i32 %tmp16, 2
69 %tmp36 = icmp ugt i32 %tmp16, 52
70 br i1 %tmp36, label %bb3, label %bb13
71 }