<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 13, 2021 at 2:06 PM Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Apr 13, 2021 at 9:56 PM Jordan Rupprecht <<a href="mailto:rupprecht@google.com" target="_blank">rupprecht@google.com</a>> wrote:<br>
><br>
> We're seeing a clang crash (Instruction does not dominate all uses) as a result of this patch. With asserts enabled, I see:<br>
><br>
> assert.h assertion failed at llvm/lib/Analysis/LazyValueInfo.cpp:677 in Optional<llvm::ValueLatticeElement> (anonymous namespace)::LazyValueInfoImpl::solveBlockValueNonLocal(llvm::Value *, llvm::BasicBlock *): isa<Argument>(Val) && "Unknown live-in to the entry block"<br>
><br>
> Mind if we revert this patch while we come up with a reduction? And/or is the error message above enough to clue you on what the right fix is?<br>
><br>
> The reproduction requires FDO, so reduction is trickier :( but I'll get started<br>
Which pass crashes? CVP?<br></blockquote><div> </div><div>The crash we see with release builds doesn't have a stack trace, so I'm not sure which pass it is. The full error is: </div><div class="gmail_quote">"""</div>Instruction does not dominate all uses!<br>  %177 = phi i1 [ %175, %173 ], [ false, %165 ]<br>  %170 = select i1 %177, i8* bitcast (%"class.std::__u::basic_string_view"* @<foo> to i8*), i8* bitcast (%"class.std::__u::basic_string_view"* @<bar> to i8*)<br>fatal error: error in backend: Broken module found, compilation aborted!<br>clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)<br><div>"""</div><div>The assertion failure we see in a debug-built clang happens in llvm::CorrelatedValuePropagationPass::run</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Does this happen exactly with this patch, or with some later change?<br></blockquote><div>The "Instruction does not dominate all uses!" failure in release builds bisects to this patch. I'm having some difficulties with bisecting the assertion failure (because of the FDO issue), but it doesn't happen in a weeks-old compiler. So either it bisects to the same thing, or something else that's very new. I can keep looking at that.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What if you dump full module IR before the pass, and run just that<br>
single pass via `opt`, does it crash?<br>
<br>
Unless the assertion is triggered because the [base?] compiler was miscompiled,<br>
i think that assertion is simply over-eager and should be removed.<br>
But i won't be able to tell without the testcase.<br></blockquote><div>(still working on a test case)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Roman<br>
<br>
> On Fri, Apr 9, 2021 at 4:56 PM Roman Lebedev via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
>><br>
>><br>
>> Author: Roman Lebedev<br>
>> Date: 2021-04-10T00:56:28+03:00<br>
>> New Revision: 077bff39d46364035a5dcfa32fc69910ad0975d0<br>
>><br>
>> URL: <a href="https://github.com/llvm/llvm-project/commit/077bff39d46364035a5dcfa32fc69910ad0975d0" rel="noreferrer" target="_blank" class="cremed">https://github.com/llvm/llvm-project/commit/077bff39d46364035a5dcfa32fc69910ad0975d0</a><br>
>> DIFF: <a href="https://github.com/llvm/llvm-project/commit/077bff39d46364035a5dcfa32fc69910ad0975d0.diff" rel="noreferrer" target="_blank" class="cremed">https://github.com/llvm/llvm-project/commit/077bff39d46364035a5dcfa32fc69910ad0975d0.diff</a><br>
>><br>
>> LOG: [Analysis] isDereferenceableAndAlignedPointer(): recurse into select's hands<br>
>><br>
>> By doing this within the method itself,<br>
>> we support traversing multiple levels of selects (TODO: PHI's),<br>
>> fixing the SROA `std::clamp()` testcase.<br>
>><br>
>> Fixes <a href="https://bugs.llvm.org/show_bug.cgi?id=47271" rel="noreferrer" target="_blank" class="cremed">https://bugs.llvm.org/show_bug.cgi?id=47271</a><br>
>> Mostly fixes <a href="https://bugs.llvm.org/show_bug.cgi?id=49909" rel="noreferrer" target="_blank" class="cremed">https://bugs.llvm.org/show_bug.cgi?id=49909</a><br>
>><br>
>> Added:<br>
>><br>
>><br>
>> Modified:<br>
>>     llvm/lib/Analysis/Loads.cpp<br>
>>     llvm/test/Transforms/SROA/std-clamp.ll<br>
>><br>
>> Removed:<br>
>><br>
>><br>
>><br>
>> ################################################################################<br>
>> diff  --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp<br>
>> index 8d01ea045097..2ae1fd5b5bde 100644<br>
>> --- a/llvm/lib/Analysis/Loads.cpp<br>
>> +++ b/llvm/lib/Analysis/Loads.cpp<br>
>> @@ -59,6 +59,16 @@ static bool isDereferenceableAndAlignedPointer(<br>
>>    // Note that it is not safe to speculate into a malloc'd region because<br>
>>    // malloc may return null.<br>
>><br>
>> +  // Recurse into both hands of select.<br>
>> +  if (const SelectInst *Sel = dyn_cast<SelectInst>(V)) {<br>
>> +    return isDereferenceableAndAlignedPointer(Sel->getTrueValue(), Alignment,<br>
>> +                                              Size, DL, CtxI, DT, TLI, Visited,<br>
>> +                                              MaxDepth) &&<br>
>> +           isDereferenceableAndAlignedPointer(Sel->getFalseValue(), Alignment,<br>
>> +                                              Size, DL, CtxI, DT, TLI, Visited,<br>
>> +                                              MaxDepth);<br>
>> +  }<br>
>> +<br>
>>    // bitcast instructions are no-ops as far as dereferenceability is concerned.<br>
>>    if (const BitCastOperator *BC = dyn_cast<BitCastOperator>(V)) {<br>
>>      if (BC->getSrcTy()->isPointerTy())<br>
>><br>
>> diff  --git a/llvm/test/Transforms/SROA/std-clamp.ll b/llvm/test/Transforms/SROA/std-clamp.ll<br>
>> index 561904252288..c0132a519722 100644<br>
>> --- a/llvm/test/Transforms/SROA/std-clamp.ll<br>
>> +++ b/llvm/test/Transforms/SROA/std-clamp.ll<br>
>> @@ -6,18 +6,14 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16<br>
>>  define float @_Z8stdclampfff(float %x, float %lo, float %hi) {<br>
>>  ; CHECK-LABEL: @_Z8stdclampfff(<br>
>>  ; CHECK-NEXT:  bb:<br>
>> -; CHECK-NEXT:    [[I:%.*]] = alloca float, align 4<br>
>> -; CHECK-NEXT:    [[I3:%.*]] = alloca float, align 4<br>
>>  ; CHECK-NEXT:    [[I4:%.*]] = alloca float, align 4<br>
>> -; CHECK-NEXT:    store float [[X:%.*]], float* [[I]], align 4<br>
>> -; CHECK-NEXT:    store float [[LO:%.*]], float* [[I3]], align 4<br>
>>  ; CHECK-NEXT:    store float [[HI:%.*]], float* [[I4]], align 4<br>
>> -; CHECK-NEXT:    [[I5:%.*]] = fcmp fast olt float [[X]], [[LO]]<br>
>> +; CHECK-NEXT:    [[I5:%.*]] = fcmp fast olt float [[X:%.*]], [[LO:%.*]]<br>
>>  ; CHECK-NEXT:    [[I6:%.*]] = fcmp fast olt float [[HI]], [[X]]<br>
>> -; CHECK-NEXT:    [[I7:%.*]] = select i1 [[I6]], float* [[I4]], float* [[I]]<br>
>> -; CHECK-NEXT:    [[I8:%.*]] = select i1 [[I5]], float* [[I3]], float* [[I7]]<br>
>> -; CHECK-NEXT:    [[I9:%.*]] = load float, float* [[I8]], align 4<br>
>> -; CHECK-NEXT:    ret float [[I9]]<br>
>> +; CHECK-NEXT:    [[I9_SROA_SPECULATE_LOAD_FALSE_SROA_SPECULATE_LOAD_TRUE:%.*]] = load float, float* [[I4]], align 4<br>
>> +; CHECK-NEXT:    [[I9_SROA_SPECULATE_LOAD_FALSE_SROA_SPECULATED:%.*]] = select i1 [[I6]], float [[I9_SROA_SPECULATE_LOAD_FALSE_SROA_SPECULATE_LOAD_TRUE]], float [[X]]<br>
>> +; CHECK-NEXT:    [[I9_SROA_SPECULATED:%.*]] = select i1 [[I5]], float [[LO]], float [[I9_SROA_SPECULATE_LOAD_FALSE_SROA_SPECULATED]]<br>
>> +; CHECK-NEXT:    ret float [[I9_SROA_SPECULATED]]<br>
>>  ;<br>
>>  bb:<br>
>>    %i = alloca float, align 4<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
>> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="cremed">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>