This is an archive of the discontinued LLVM Phabricator instance.

[IR] fix crash in Constant::isElementWiseEqual() with FP types
ClosedPublic

Authored by spatel on Jan 15 2020, 9:44 AM.

Details

Summary

We lifted this code from InstCombine for general usage in:
rL369842
...but it's not safe as-is. There are no existing users that can trigger this bug, but I discovered it via crashing several regression tests when trying to use it for select folding in InstSimplify.

ICmp requires (vector) integer types, so bitcast the constants before trying the match. That matches the definition of "equal or undef" that I was looking for. If someone wants an FP-aware version of equality (deal with NaN, -0.0), that could be a different mode or different function.

Diff Detail

Event Timeline

spatel created this revision.Jan 15 2020, 9:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2020, 9:44 AM
nikic added inline comments.Jan 15 2020, 1:47 PM
llvm/lib/IR/Constants.cpp
295–299

Probably not going to work for vectors of pointers though. Is that relevant to your use-case?

spatel marked an inline comment as done.Jan 15 2020, 2:31 PM
spatel added inline comments.
llvm/lib/IR/Constants.cpp
295–299

Yes, good catch. It was not my immediate concern, and I'm not sure how to handle pointers. So I think it's ok to just bail out on those. I'll add to the tests though.

spatel updated this revision to Diff 238373.Jan 15 2020, 2:42 PM

Patch updated:
Bail out on anything not integer or FP. I'm not sure how to deal with pointers, but added a few basic tests in case we do eventually support those.

nikic accepted this revision.Jan 16 2020, 11:33 AM

LGTM

This revision is now accepted and ready to land.Jan 16 2020, 11:33 AM
This revision was automatically updated to reflect the committed changes.