This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine][sse4a] Fix assertion failure caused by unsafe dyn_casts on the operands of extrq/extrqi intrinsic calls.
ClosedPublic

Authored by andreadb on Sep 6 2016, 7:57 AM.

Details

Summary

This patch fixes an assertion failure caused by unsafe dynamic casts on the constant operands of sse4a intrinsic calls to extrq/extrqi.

The combine logic that simplifies sse4a extrq/extrqi intrinsic calls currently checks if the input operands are constants. Internally, the logic relies on unsafe dyn_casts on the values returned by calls to method Constant::getAggregateElement.
However, method 'getAggregateElement ' may return null if the constant element cannot be retrieved. So all the dyn_cast can potentially fail. This is what happens for example if a constexpr values is passed in input to the extrq/extrqi intrinsic calls.

I have added two test cases that fail with the following assertion failure:

include/llvm/Support/Casting.h:95: static bool
llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::ConstantInt; From =
llvm::Constant]: Assertion `Val && "isa<> used on a null pointer"' failed

This patch fixes the problem by using a dyn_cast_or_null (instead of a simple dyn_cast on the result of calls to Constant::getAggregateElement.

Please let me know if okay to commit.

Thanks,
Andrea

Diff Detail

Repository
rL LLVM

Event Timeline

andreadb updated this revision to Diff 70396.Sep 6 2016, 7:57 AM
andreadb retitled this revision from to [InstCombine][sse4a] Fix assertion failure caused by unsafe dyn_casts on the operands of extrq/extrqi intrinsic calls..
andreadb updated this object.
andreadb added reviewers: RKSimon, majnemer.
andreadb added a subscriber: llvm-commits.
RKSimon edited edge metadata.Sep 6 2016, 1:34 PM

Thanks Andrea, does INSERTQI have a similar problem?

Thanks Andrea, does INSERTQI have a similar problem?

Possibly. We are currently running extensive tests. So far, the extrq is the only problematic one. I wouldn't be surprised if that happens with the INSERTQI though (I saw that there is similar code in there). I will run some experiments and I will let you know in case.
Would it be okay if in the meatime I commit this change?

Have a nice day,
Andrea

RKSimon accepted this revision.Sep 7 2016, 4:07 AM
RKSimon edited edge metadata.

LGTM as long as you check if INSERTQ/INSERTQI is affected as well, if so you're probably good to just commit the equivalent fix/tests as a followup.

This revision is now accepted and ready to land.Sep 7 2016, 4:07 AM

LGTM as long as you check if INSERTQ/INSERTQI is affected as well, if so you're probably good to just commit the equivalent fix/tests as a followup.

Sure, I will test INSERTQ/INSERTQI as well.

Thanks Simon

This revision was automatically updated to reflect the committed changes.