This patch teaches lookThroughFPExtensions to support shrinking a vector of ConstantFPs. This should improve our ability to combine vector fptrunc with fp binops.
Details
Diff Detail
Event Timeline
lib/Transforms/InstCombine/InstCombineCasts.cpp | ||
---|---|---|
1441–1443 | The existing code has a bug, but I don't think there's a way to expose it other than as an inefficiency. We will (usually?) create a half constant and then extend it back to single because that's not the type we wanted in the first place. For scalars, this is wasteful, but constant folding hides the problem. Maybe nobody cares for scalars, but now we're doing that extra work N times for vector constants. And the bug is now visible (so we should add a test like this where the constants can't shrink to the same narrow type): define <2 x float> @not_half_shrinkable(<2 x float> %x) { %ext = fpext <2 x float> %x to <2 x double> %add = fadd <2 x double> %ext, <double 0.0, double 2049.0> %r = fptrunc <2 x double> %add to <2 x float> ret <2 x float> %r } | |
1479–1483 | The usual pattern has the vector constant check inside the helper function, so move the vector type check into 'shrinkFPConstantVector' and rename the functions? Ideally, these wouldn't be instcombine-specific helpers. They'd be queries on constants. I recently made a similar change in rL325398. | |
test/Transforms/InstCombine/fpextend.ll | ||
65–69 | I think we can remove the load/store/globals from all of the tests in this file as a preliminary cleanup. |
The scalar code is now type based and doesn't new constants. Rework this patch to build on that and find a minimal safe type by looking at each element. Then turn that into a vector type.
LGTM, but please add a TODO comment (and ideally a test to show it) that we don't handle vectors with undef elements.
The existing code has a bug, but I don't think there's a way to expose it other than as an inefficiency. We will (usually?) create a half constant and then extend it back to single because that's not the type we wanted in the first place.
For scalars, this is wasteful, but constant folding hides the problem. Maybe nobody cares for scalars, but now we're doing that extra work N times for vector constants. And the bug is now visible (so we should add a test like this where the constants can't shrink to the same narrow type):