This is an archive of the discontinued LLVM Phabricator instance.

[IPSCCP][FuncSpec] Fix compiler crash 60191.
ClosedPublic

Authored by labrinea on Jan 24 2023, 2:24 AM.

Details

Summary

Found here https://github.com/llvm/llvm-project/issues/60191

The compiler would crash when specializing a function based on a function pointer whose call sites may expect less parameters than those of the function we are replacing the pointer with.

Fixes #60191

Diff Detail

Event Timeline

labrinea created this revision.Jan 24 2023, 2:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 24 2023, 2:24 AM
labrinea requested review of this revision.Jan 24 2023, 2:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 24 2023, 2:24 AM
nikic added a subscriber: nikic.Jan 24 2023, 2:31 AM
nikic added inline comments.
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
627

Is it okay if the arguments have different types? (If no, then you'll want to compare getFunctionType()).

llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
2

Can you avoid the triple in the test?

Also, is it possible to reduce the test such that it only requires running ipsccp, and not the whole opt pipeline?

labrinea added inline comments.Jan 24 2023, 2:38 AM
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
627

Good point, I'll look into it.

llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
2

I couldn't get the compiler crash without the triple, or if I further reduced the test. I'll try harder. If I change the pass to "ipsccp<func-spec>" or just "ipsccp" (func-spec is implied by default) the test will still crash.

jhuber6 added a subscriber: arsenm.Jan 24 2023, 5:54 AM
jhuber6 added inline comments.
llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
2

The fact that this crashes only on amdgcn-amd-amdhsa is weird, see https://godbolt.org/z/1h1fdPs4c. @arsenm, do you have any idea what it could be? It works fine with nvptx64-nvidia-cuda FWIW.

labrinea added inline comments.Jan 24 2023, 6:26 AM
llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
2

It's not crashing only on that target, I have successfully reduced it further. Will upload a revised patch soon.

labrinea updated this revision to Diff 491791.Jan 24 2023, 7:37 AM

Changes from last revision:

  • early exit the calculation of specialization bonus when the function type mismatches instead of just the number of arguments
  • reduced the test case further, removed the target triple, and specified the ipsccp pass only instead of O3
nikic added inline comments.Jan 24 2023, 7:44 AM
llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
2

Missing | FileCheck %s, so your CHECK-DAG lines below don't do anything...

labrinea added inline comments.Jan 24 2023, 7:48 AM
llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
2

Oops

labrinea updated this revision to Diff 491801.Jan 24 2023, 7:53 AM

Added the missing filecheck command to the run line of the test.

nikic accepted this revision.Jan 24 2023, 9:02 AM

LGTM

This revision is now accepted and ready to land.Jan 24 2023, 9:02 AM
jhuber6 accepted this revision.Jan 24 2023, 9:03 AM
jhuber6 edited the summary of this revision. (Show Details)

If this is merged after we branch off, please backport :)

This revision was automatically updated to reflect the committed changes.