This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFolding] Constant folding for integer vector reduce intrinsics
ClosedPublic

Authored by dmgreen on May 25 2020, 4:45 AM.

Details

Summary

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.

Diff Detail

Event Timeline

dmgreen created this revision.May 25 2020, 4:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2020, 4:45 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

Do we need to explicitly handle an undef vector here?

llvm/lib/Analysis/ConstantFolding.cpp
1662

Please use dyn_cast<> where appropriate.

dmgreen updated this revision to Diff 266122.May 26 2020, 2:04 AM

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.

efriedma accepted this revision.May 26 2020, 11:49 AM

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.

This revision is now accepted and ready to land.May 26 2020, 11:49 AM
This revision was automatically updated to reflect the committed changes.