opt hangs in LoadStoreVectorizer
| Bugzilla Link | 38517 |
| Version | trunk |
| OS | Linux |
| Attachments | reproducer with nested load |
| CC | @bevin-hansson,@mikaelholmen |
Extended Description
Running opt -load-store-vectorizer -o tmp.opt.ll tmp.ll with the attached reproducer, the LoadStoreVectorizer hangs in an endless loop.
The originating src program consists of a nested load, where the inner load's result is used for indexing the outer load.
A somewhat shallow analysis by me indicates that the areConsecutivePointers() function do some SCEV magic to find that the pointers for these loads are consecutive, but it doesn't seem to me that they are. Then when vectorization has been performed, the IR references has a loop, and when the reorder() function is applied to it, it follows that loop endlessly.
This is the original c-program for reference:
#include <stdint.h>
uint32_t a = 0; uint32_t b[1][3] = { { 0, 0, 0 } }; const uint16_t c = 1;
int main() { b[(2u & b[a % 1][2u % 3]) % 1][c % 3]; }
Based on the patch above, a few more reproducers to increase the coverage of the problem:
target triple = "aarch64"
; Function Attrs: noinline nounwind define i32 @test([2 x i32]* %array) #0 { entry: %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %array, i32 0, i32 1 %t = load i32, i32* %arrayidx, align 4 %rem = urem i32 %t, 1 %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %array, i32 %rem, i32 0 %v = load i32, i32* %arrayidx2, align 4 %r = add i32 %v, %t ret i32 %r }
attributes #0 = { noinline nounwind }
target triple = "aarch64"
; Function Attrs: noinline nounwind define i32 @test([2 x i32]* %array, i32 %idx) #0 { entry: %ptr1 = getelementptr inbounds [2 x i32], [2 x i32]* %array, i32 %idx, i32 1 %t = load i32, i32* %ptr1, align 4 %t2 = mul i32 %t, 2 %idx.p.2t = add i32 %idx, %t2 %idx.p.t = sub i32 %idx.p.2t, %t %idx.another = sub i32 %idx.p.t, %t %ptr0 = getelementptr inbounds [2 x i32], [2 x i32]* %array, i32 %idx.another, i32 0 %v = load i32, i32* %ptr0, align 4 %r = add i32 %v, %t ret i32 %r }
attributes #0 = { noinline nounwind }
target triple = "aarch64"
; Function Attrs: noinline nounwind define i32 @test(i32* %array, i32 %idx, i1 %cond, i1 %cond2) #0 { entry: %idx.p.7 = add nsw i32 %idx, 7 %idx.p.7.sext = sext i32 %idx.p.7 to i64 %ptr1.dummy = getelementptr inbounds i32, i32* %array, i64 21 %ptr1.true = getelementptr inbounds i32, i32* %array, i64 1 %ptr1.false = getelementptr inbounds i32, i32* %array, i64 %idx.p.7.sext %ptr1.tmp = select i1 %cond, i32* %ptr1.true, i32* %ptr1.false %ptr1 = select i1 %cond2, i32* %ptr1.tmp, i32* %ptr1.dummy %t = load i32, i32* %ptr1, align 4 %t2 = mul i32 %t, 2 %idx.p.2t = add i32 %idx, %t2 %idx.p.t = sub i32 %idx.p.2t, %t %idx.another = sub i32 %idx.p.t, %t %idx.p.6 = add i32 %idx.another, 6 %idx.p.6.sext = sext i32 %idx.p.6 to i64 %ptr0.dummy = getelementptr inbounds i32, i32* %array, i64 20 %ptr0.true = getelementptr inbounds i32, i32* %array, i64 0 %ptr0.false = getelementptr inbounds i32, i32* %array, i64 %idx.p.6.sext %ptr0.tmp = select i1 %cond, i32* %ptr0.true, i32* %ptr0.false %ptr0 = select i1 %cond2, i32* %ptr0.tmp, i32* %ptr0.dummy %v = load i32, i32* %ptr0, align 4 %r = add i32 %v, %t ret i32 %r }
attributes #0 = { noinline nounwind }
Please see https://reviews.llvm.org/D54468#1395738 for details.
Patch suggestion: https://reviews.llvm.org/D54468
The fix has been reverted in 9671ed1afcd (#106245).