This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Avoid passing pow attributes to sqrt
ClosedPublic

Authored by Saldivarcher on Nov 4 2022, 11:44 AM.

Details

Summary

As described on this issue, instcombine seems to be passing the attributes of pow to sqrt. This in turn causes an assertion to be hit later on.

Here is how to get the assertion:

$ cat small.ll 
define void @PR58475(double %x) {
  %call = call afn double @pow(double %x, double 1.5)
  ret void
}

declare double @pow(double noundef, double noundef)
$ opt -instcombine small.ll -disable-output

Diff Detail

Event Timeline

Saldivarcher created this revision.Nov 4 2022, 11:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 11:44 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Saldivarcher requested review of this revision.Nov 4 2022, 11:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 11:44 AM

Please add the crashing example as a regression test. I'm not sure if we can modify an existing file to show the crash without changing a bunch of other tests, so it can be a new file in the llvm-project/llvm/test/Transforms/InstCombine dir.

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2106

If we don't need the Attrs for any other transforms, it would be better to declare/init it just above the code where it is used.

Okay, test was added, hopefully it looks reasonable. Let me know if I need to change/update anything.

Saldivarcher added inline comments.Nov 4 2022, 4:13 PM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2106

Just seen this, let me declare above the call.

spatel added inline comments.Nov 6 2022, 5:24 AM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2169

Do we need to name the default/empty AttributeList if this is the only use?
Ie, can the code be shorter?

Sqrt = getSqrtCall(Base, AttributeList(), Pow->doesNotAccessMemory(), M, B, TLI);
spatel added inline comments.Nov 6 2022, 6:15 AM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2169

I tried to make the existing code around here easier to understand with:
bff6880a5f89

Saldivarcher added inline comments.Nov 6 2022, 10:56 AM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2169

Your changes LGTM, I like the Attrs -> NoAttrs change, really helps with readability. The AttributeList() change is alright as well. Should this change just include the test then? Or should I close it completely?

spatel added inline comments.Nov 6 2022, 1:51 PM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2169

I left this case alone, so there wouldn't be a conflict. You can either name the variable "NoAttrs" or default construct it in the getSqrtCall(), and then we should be good. Do you have commit access?

Saldivarcher added inline comments.
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
2169

Oops, I misread your commit, I thought you handled this case! But okay, I updated the code to use AttributeList(). No, I don't have commit access :( Can you commit this for me?

spatel accepted this revision.Nov 7 2022, 5:23 AM

LGTM

This revision is now accepted and ready to land.Nov 7 2022, 5:23 AM
This revision was automatically updated to reflect the committed changes.