This is an archive of the discontinued LLVM Phabricator instance.

[Power10] Implement Vector Replace Builtins in LLVM/Clang
AbandonedPublic

Authored by biplmish on Jun 23 2020, 1:25 AM.

Details

Reviewers
amyk
nemanjai
steven.zhang
lei
Group Reviewers
Restricted Project
Summary

This patch implements builtins for the following prototypes:

vector signed int vec_replace_elt (vector signed int, signed int, const int);
vector unsigned int vec_replace_elt (vector unsigned int, unsigned int, const int);
vector float vec_replace_elt (vector float, float, const int);
vector signed long long vec_replace_elt (vector signed long long, signed long long, const int);
vector unsigned long long vec_replace_elt (vector unsigned long long, unsigned long long, const int);
vector double rec_replace_elt (vector double, double, const int);

vector unsigned char vec_replace_unaligned (vector unsigned char, signed int, const int);
vector unsigned char vec_replace_unaligned (vector unsigned char, unsigned int, const int);
vector unsigned char vec_replace_unaligned (vector unsigned char, float, const int);
vector unsigned char vec_replace_unaligned (vector unsigned char, signed long long, const int);
vector unsigned char vec_replace_unaligned (vector unsigned char, unsigned long long, const int);
vector unsigned char vec_replace_unaligned (vector unsigned char, double, const int);

Diff Detail

Event Timeline

biplmish created this revision.Jun 23 2020, 1:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2020, 1:25 AM
lei added a subscriber: lei.Jun 23 2020, 7:57 AM
lei added inline comments.
clang/lib/Headers/altivec.h
16833

Nit: It would be good if we can keep the indentation for these definitions consistent.

llvm/include/llvm/IR/IntrinsicsPowerPC.td
429

nit: // P10 Vector Insert with immediate.
Please end all sentences with a .
Space after //

llvm/lib/Target/PowerPC/PPCInstrPrefix.td
211

nit: missing .

579

nit: indentation.

581

indentation.

amyk added inline comments.Jun 23 2020, 8:34 AM
clang/include/clang/Basic/BuiltinsPPC.def
309

End with a period.

clang/lib/Headers/altivec.h
16834

Nit: Space after the comment of the name.

steven.zhang added inline comments.Jun 23 2020, 5:58 PM
clang/lib/Headers/altivec.h
16839

I see that the value range for __c is 0, 3. Could you add some semantic check in frontend about this?

biplmish marked an inline comment as done.Jun 23 2020, 11:53 PM
biplmish added inline comments.
clang/lib/Headers/altivec.h
16839

Yes value of __c should actually be 0.3 for 32 bit type and 0,1 for 64bit type. Also this is converted to a byte index as input to builtin as specified. So a range check for builtin input would be 0-12 for 32 bit type and 0-8 for 64 bit type.

biplmish updated this revision to Diff 272984.Jun 24 2020, 5:00 AM

Review comments incorporated.

steven.zhang added inline comments.Jun 28 2020, 9:35 PM
clang/lib/Sema/SemaChecking.cpp
3127

Please add the diagnose message tests.

biplmish updated this revision to Diff 275368.Jul 3 2020, 5:22 AM

Update the builtin implementation to incorporate instruction changes.

lei requested changes to this revision.Jul 3 2020, 2:05 PM

This patch doesn't contain full context. Please regenerate with -U999999.

This revision now requires changes to proceed.Jul 3 2020, 2:05 PM
lei added inline comments.Jul 3 2020, 3:12 PM
clang/test/CodeGen/builtins-ppc-p10vector.c
532

No need for this, please use default and remove the CHECK-LE run line as it's the same as the default run line.

biplmish updated this revision to Diff 275491.Jul 4 2020, 3:01 AM

Updating the patch with latest code and modification to the redundant test case run.

lei added inline comments.Jul 6 2020, 6:38 AM
clang/lib/Headers/altivec.h
16840

This looks just like a cast to unsigned int, can you explain why it needs to be cast to a union to extract the unsigned int instead of just directly casting it to an unsigned int?

16847

nit: remove extra empty line.

clang/test/CodeGen/builtins-ppc-p10vector.c
103

I don't see why you have 2 different CHECK prefix for the same run line. Seems redundant to me. Please update to just use CHECK.

biplmish added inline comments.Jul 6 2020, 8:15 AM
clang/lib/Headers/altivec.h
16840

The intrinsic implements the input2 argument as i64. When the input to the function is of type float/double it generates fptoui which can modify the user input value.
Cast to union is done to preserve the float value and the same reaches the hw instruction.

biplmish updated this revision to Diff 275723.Jul 6 2020, 8:17 AM

Modify the clang test to remove the redundant CHECK-LE's.

lei added inline comments.Jul 6 2020, 9:38 AM
clang/test/CodeGen/builtins-ppc-p10vector.c
5–6

Should not remove this since there are tests in here that depends on this this check prefix.

biplmish updated this revision to Diff 275748.Jul 6 2020, 9:56 AM

Add the CHECK-LE run because there are dependent tests.

biplmish abandoned this revision.Jul 7 2020, 7:54 AM

This patch will be implemented as 2 separate patches for LLVM and CLANG respectively.