gnu: mariadb: Fix CVE-2021-27928.
[jackhill/guix/guix.git] / gnu / packages / patches / llvm-9-fix-scev-miscompilation.patch
CommitLineData
851a7caf
JK
1Guix note: this got detected with the test suite of rustc 1.41.1, but
2the issue potentially affects all consumers of LLVM.
3
4From 58e8c793d0e43150a6452e971a32d7407a8a7401 Mon Sep 17 00:00:00 2001
5From: Tim Northover <tnorthover@apple.com>
6Date: Mon, 30 Sep 2019 07:46:52 +0000
7Subject: [PATCH] Revert "[SCEV] add no wrap flag for SCEVAddExpr."
8
9This reverts r366419 because the analysis performed is within the context of
10the loop and it's only valid to add wrapping flags to "global" expressions if
11they're always correct.
12
13llvm-svn: 373184
14---
15 llvm/lib/Analysis/ScalarEvolution.cpp | 2 +-
16 llvm/test/Analysis/ScalarEvolution/limit-depth.ll | 2 +-
17 llvm/test/Analysis/ScalarEvolution/nsw.ll | 2 +-
18 llvm/test/Analysis/ScalarEvolution/trip-count12.ll | 2 +-
19 llvm/test/Analysis/ScalarEvolution/trip-count9.ll | 8 ++++----
20 5 files changed, 8 insertions(+), 8 deletions(-)
21
22diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
23index 354ae05bb841..c29fc5dbccfb 100644
9e4c24ef
MC
24--- llvm/lib/Analysis/ScalarEvolution.cpp
25+++ llvm/lib/Analysis/ScalarEvolution.cpp
851a7caf
JK
26@@ -4992,7 +4992,7 @@ const SCEV *ScalarEvolution::createSimpleAffineAddRec(PHINode *PN,
27 // overflow.
28 if (auto *BEInst = dyn_cast<Instruction>(BEValueV))
29 if (isLoopInvariant(Accum, L) && isAddRecNeverPoison(BEInst, L))
30- (void)getAddRecExpr(getAddExpr(StartVal, Accum, Flags), Accum, L, Flags);
31+ (void)getAddRecExpr(getAddExpr(StartVal, Accum), Accum, L, Flags);
32
33 return PHISCEV;
34 }
35diff --git a/llvm/test/Analysis/ScalarEvolution/limit-depth.ll b/llvm/test/Analysis/ScalarEvolution/limit-depth.ll
36index db68a4f84c91..6fdf8c5df974 100644
9e4c24ef
MC
37--- llvm/test/Analysis/ScalarEvolution/limit-depth.ll
38+++ llvm/test/Analysis/ScalarEvolution/limit-depth.ll
851a7caf
JK
39@@ -46,7 +46,7 @@ define void @test_mul(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
40 define void @test_sext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) {
41 ; CHECK-LABEL: @test_sext
42 ; CHECK: %se2 = sext i64 %iv2.inc to i128
43-; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a)<nsw> to i64),+,1}<nsw><%loop> to i128))<nsw>,+,1}<nsw><%loop2>
44+; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a) to i64),+,1}<nsw><%loop> to i128))<nsw>,+,1}<nsw><%loop2>
45 entry:
46 br label %loop
47
48diff --git a/llvm/test/Analysis/ScalarEvolution/nsw.ll b/llvm/test/Analysis/ScalarEvolution/nsw.ll
49index 69427368625d..ca24f9d4a04b 100644
9e4c24ef
MC
50--- llvm/test/Analysis/ScalarEvolution/nsw.ll
51+++ llvm/test/Analysis/ScalarEvolution/nsw.ll
851a7caf
JK
52@@ -163,7 +163,7 @@ bb5: ; preds = %bb2
53 declare void @f(i32)
54
55 ; CHECK-LABEL: nswnowrap
56-; CHECK: --> {(1 + %v)<nsw>,+,1}<nsw><%for.body>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: (2 + %v)
57+; CHECK: --> {(1 + %v)<nsw>,+,1}<nsw><%for.body>{{ U: [^ ]+ S: [^ ]+}}{{ *}}Exits: (1 + ((1 + %v)<nsw> smax %v))
58 define void @nswnowrap(i32 %v, i32* %buf) {
59 entry:
60 %add = add nsw i32 %v, 1
61diff --git a/llvm/test/Analysis/ScalarEvolution/trip-count12.ll b/llvm/test/Analysis/ScalarEvolution/trip-count12.ll
62index 5e7d72d5e4f3..d0086ee2e6ac 100644
9e4c24ef
MC
63--- llvm/test/Analysis/ScalarEvolution/trip-count12.ll
64+++ llvm/test/Analysis/ScalarEvolution/trip-count12.ll
851a7caf
JK
65@@ -1,7 +1,7 @@
66 ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
67
68 ; CHECK: Determining loop execution counts for: @test
69-; CHECK: Loop %for.body: backedge-taken count is ((-2 + %len)<nsw> /u 2)
70+; CHECK: Loop %for.body: backedge-taken count is ((-2 + %len) /u 2)
71 ; CHECK: Loop %for.body: max backedge-taken count is 1073741823
72
73 define zeroext i16 @test(i16* nocapture %p, i32 %len) nounwind readonly {
74diff --git a/llvm/test/Analysis/ScalarEvolution/trip-count9.ll b/llvm/test/Analysis/ScalarEvolution/trip-count9.ll
75index c0a1d12fa00e..9a080b34743f 100644
9e4c24ef
MC
76--- llvm/test/Analysis/ScalarEvolution/trip-count9.ll
77+++ llvm/test/Analysis/ScalarEvolution/trip-count9.ll
851a7caf
JK
78@@ -179,7 +179,7 @@ exit:
79 }
80
81 ; CHECK: Determining loop execution counts for: @nsw_startx
82-; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x)<nsw> smax %n))
83+; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n))
84 ; CHECK: Loop %loop: max backedge-taken count is -1
85 define void @nsw_startx(i4 %n, i4 %x) {
86 entry:
87@@ -195,7 +195,7 @@ exit:
88 }
89
90 ; CHECK: Determining loop execution counts for: @nsw_startx_step2
91-; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x)<nsw> smax %n)) /u 2)
92+; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2)
93 ; CHECK: Loop %loop: max backedge-taken count is 7
94 define void @nsw_startx_step2(i4 %n, i4 %x) {
95 entry:
96@@ -381,7 +381,7 @@ exit:
97 }
98
99 ; CHECK: Determining loop execution counts for: @even_nsw_startx
100-; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x)<nsw> smax (2 * %n)))
101+; CHECK: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n)))
102 ; CHECK: Loop %loop: max backedge-taken count is -2
103 define void @even_nsw_startx(i4 %n, i4 %x) {
104 entry:
105@@ -398,7 +398,7 @@ exit:
106 }
107
108 ; CHECK: Determining loop execution counts for: @even_nsw_startx_step2
109-; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x)<nsw> smax (2 * %n))) /u 2)
110+; CHECK: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2)
111 ; CHECK: Loop %loop: max backedge-taken count is 7
112 define void @even_nsw_startx_step2(i4 %n, i4 %x) {
113 entry: