This is an archive of the discontinued LLVM Phabricator instance.

[Altivec] Change vec_sl to a << (b % (sizeof(a) * 8))
ClosedPublic

Authored by timshen on Dec 21 2016, 4:02 PM.

Details

Summary

For a << b (as original vec_sl does), if b >= sizeof(a) * 8, the
behavior is undefined. However, Power instructions do define the
behavior, which is equivalent to a << (b % (sizeof(a) * 8)).

This patch changes altivec.h to use a << (b % (sizeof(a) * 8)), to ensure
the consistent semantic of the instructions. Then it combines
the generated multiple instructions back to a single shift.

This patch handles left shift only. Right shift, on the other hand, is more
complicated, considering arithematic/logical right shift.

Diff Detail

Repository
rL LLVM

Event Timeline

timshen updated this revision to Diff 82285.Dec 21 2016, 4:02 PM
timshen retitled this revision from to [PowerPC, DAGCombiner] Change vec_sl to a << (b % (sizeof(a) * 8)), and fold it back to a << b..
timshen updated this object.
timshen added subscribers: llvm-commits, cfe-commits.
echristo edited edge metadata.Jan 3 2017, 4:13 PM

One inline comment for the clang part and then let's split the llvm part out into a separate patch please.

Thanks!

-eric

clang/lib/Headers/altivec.h
8045 ↗(On Diff #82285)

Can you add a note here that these functions are documented to return a shift with the shift operand modulo the size of the type?

echristo accepted this revision.Jan 3 2017, 4:13 PM
echristo edited edge metadata.
This revision is now accepted and ready to land.Jan 3 2017, 4:13 PM
timshen retitled this revision from [PowerPC, DAGCombiner] Change vec_sl to a << (b % (sizeof(a) * 8)), and fold it back to a << b. to [Altivec] Change vec_sl to a << (b % (sizeof(a) * 8)).Jan 4 2017, 2:32 PM
timshen edited edge metadata.
timshen updated this revision to Diff 83140.Jan 4 2017, 2:35 PM

Update comments, and move llvm changes to another patch.

timshen marked an inline comment as done.Jan 4 2017, 2:35 PM

LGTM.

Thanks!

-eric

timshen removed a reviewer: bogner.Jan 4 2017, 3:09 PM
timshen removed a subscriber: llvm-commits.

Going to commit this?

Going to commit this?

I'd like to commit D28329 first. If we commit this now, the normal code will be slower.

This revision was automatically updated to reflect the committed changes.