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