This add constant folding for all the integer vector reduce intrinsics, providing that the argument is a constant vector. zeroinitializer always produces 0 for all intrinsics, and other values can be handled with APInt operators.
Details
Diff Detail
Event Timeline
Do we need to explicitly handle an undef vector here?
llvm/lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
1659 | Please use dyn_cast<> where appropriate. |
Do we need to explicitly handle an undef vector here?
Do you mean an undef vector or a vector with undef's in it? I can change either if you think it is worth it. I didn't so far because I couldn't find anything to automatically handle it, and didn't want to replicate the logic here if I could help it.
LGTM
I didn't so far because I couldn't find anything to automatically handle it
For individual undef elements, I guess you could use constant folding from ConstantExpr::get(). But I guess it's not that important, practically speaking.
For the case where the entire vector is undef, you could add checks to the if (isa<UndefValue>(Operands[0])) { block near the top of the function. But I guess it's not that likely to matter, anyway.
Please use dyn_cast<> where appropriate.