Expressions in vector constants

I am working on a project that uses integer vectors fairly extensively. Some values in the vectors came from constant pointers cast to 64-bit integers, and the LLVM optimizer would often end up folding values into instructions that looked like this:

store <2 x i64> <i64 ptrtoint (… constant_pointer_value … to i64), i64 0>, <2 x i64>* %f

ExecutionEngine would abort at runtime on all instructions like this because ExecutionEngine::getConstantValue assumes all vector constants are “simple constants” whose values are ConstantInts, not handling the case of ConstantExpr. I attached a patch that fixes that issue and works as intended from the limited scope of my project in case it is useful.

It certainly appears that this issue exists for other types besides Integer and for other aggregate constant types. Is there ExecutionEngine doesn’t run the full-fledged getConstantValue on all subvalues of aggregate constants instead of reaching into / directly casting subvalues?

Bret Taylor

vector-constant-expressions.patch (1.18 KB)