Page MenuHomePhabricator

[Clang] Add min/max reduction builtins.
ClosedPublic

Authored by fhahn on Oct 18 2021, 8:28 AM.

Details

Summary

This patch implements builtin_reduce_max and builtin_reduce_min as
specified in D111529.

The order of operations does not matter for min or max reductions and
they can be directly lowered to the corresponding
llvm.vector.reduce.{fmin,fmax,umin,umax,smin,smax} intrinsic calls.

Diff Detail

Event Timeline

fhahn requested review of this revision.Oct 18 2021, 8:28 AM
fhahn created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2021, 8:28 AM
craig.topper added inline comments.Oct 18 2021, 10:09 AM
clang/lib/Sema/SemaChecking.cpp
16546

Is this indented incorrectly? There appear to be 2 ifs at the same level

fhahn updated this revision to Diff 380486.Oct 18 2021, 11:27 AM

Remove stray !TyA->getAs<VectorType>() check.

fhahn marked an inline comment as done.Oct 18 2021, 11:28 AM
fhahn added inline comments.
clang/lib/Sema/SemaChecking.cpp
16546

Yes they were, thanks! The if (!TyA->getAs<VectorType>()) was a left-over from an earlier iteration. Removed.

fhahn updated this revision to Diff 380948.Oct 20 2021, 7:26 AM
fhahn marked an inline comment as done.

rebase on top of recently updated patches.

fhahn updated this revision to Diff 382240.Oct 26 2021, 2:48 AM

Rebased after recent changes in D111985 https://reviews.llvm.org/D111985: changes the return type of SemaBuiltinReduceMath to bool and drop the CallResult argument.

Also added tests with const and variables with address space and moved tests to builtins-reduction-math.c instead of builtins-elementwise-math.c

aaron.ballman added inline comments.Oct 26 2021, 5:25 AM
clang/lib/Sema/SemaChecking.cpp
16611–16614

What about type sugar?

16616

Should this type undergo the usual conversions?

fhahn updated this revision to Diff 383756.Nov 1 2021, 2:58 AM

rebase on top of recent changes.

Precommit CI looks to be failing.

/var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGen/builtins-reduction-math.c:13:9: error: initializing 'float' with an expression of incompatible type 'float4' (vector of 4 'float' values)

  float r1 = __builtin_reduce_max(vf1);
fhahn updated this revision to Diff 383900.Nov 1 2021, 2:52 PM

Precommit CI looks to be failing.

/var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGen/builtins-reduction-math.c:13:9: error: initializing 'float' with an expression of incompatible type 'float4' (vector of 4 'float' values)

  float r1 = __builtin_reduce_max(vf1);

The last version of the patch did not correctly set the return type to the element type. That should be fixed now!

This revision is now accepted and ready to land.Nov 2 2021, 4:21 AM
This revision was landed with ongoing or failed builds.Nov 2 2021, 7:02 AM
This revision was automatically updated to reflect the committed changes.