I've added a new test case that causes the scalarizer to try and use dead-and-erased values - caused by the basic blocks not being in domination order within the function. To fix this, instead of iterating through the blocks in function order, I walk them in reverse post order.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Is this the same problem as described in https://bugs.llvm.org/show_bug.cgi?id=28911 ?
I wasn't seeing the exact same failure as that bug describes - it was failing in Scalarizer::finish in the test included.
But I did pull the example from the bugzilla and tested it and it no longer crashes with my scalarizer fix.
I don't know the Scalarizer but from the descriptions of the problems I think it sounds like they are similar or the same,
and if so, there are then two possible solutions.
dstenb described a possible fix in a comment of PR28911 and we've been using that fix for a long time now for our
out-of-tree target without problems.
Perhaps that fix is a hack and using RPOT is the proper way to deal with this, I've no idea. I just wanted to point out the
possibility.
Anyway, I applied the fix in this patch on our local tree and so far so good so I don't have any objections, but I don't
really know the code enough to say it's the right thing to do.
I took a look at dstenb's approach and it is definitely not a hack - its just solving this issue from a slightly different viewpoint. Their approach just ensure thats the lists of values are never accidentally invalidated, whereas mine forces us to walk the BB graph in order such that we should never generate invalid lists in the first place.
Anyway, I applied the fix in this patch on our local tree and so far so good so I don't have any objections, but I don't
really know the code enough to say it's the right thing to do.
Great - glad it works for you!
Should I incorporate the test case from the bugzilla into this commit? Given that its a slightly different failure case that is also fixed by my change, seems like its worth ensuring it doesn't accidentally regress again.
Yes, sure that sounds good!
We have a local regression test for PR28911 that dstenb created when he applied the fix locally for our target:
; RUN: opt %s -scalarizer -verify -S -o - | FileCheck %s ; ModuleID = 'bugpoint-reduced-simplified.bc' source_filename = "bugpoint-output-32b26ac.bc" target triple = "x86_64-unknown-linux-gnu" define void @f3() local_unnamed_addr { bb1: br label %bb2 bb3: ;CHECK-LABEL: bb3: ;CHECK-NEXT: br label %bb4 %h.10.0.vec.insert = shufflevector <1 x i16> %h.10.1, <1 x i16> undef, <1 x i32> <i32 0> br label %bb4 bb2: ;CHECK-LABEL: bb2: ;CHECK: phi i16 %h.10.1 = phi <1 x i16> [ undef, %bb1 ] br label %bb3 bb4: ;CHECK-LABEL: bb4: ;CHECK: phi i16 %h.10.2 = phi <1 x i16> [ %h.10.0.vec.insert, %bb3 ] ret void }
Perhaps something like that could be used.
Incorporate a related test case that my approach also fixes from https://bugs.llvm.org/show_bug.cgi?id=28911
We are using the Scalarizer in our out-of-tree target and I've run some tests with the patch without problems so I think it's ok.
Please wait a day before submitting though in case someone who really knows this code objects, but if not I think it's ok to push.