Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Volodin Evgeniy. Lab №3 Option №1. #108

Merged
merged 9 commits into from
Apr 26, 2024

Conversation

evldn
Copy link

@evldn evldn commented Apr 23, 2024

In this lab, a pass was implemented that replaces the argument-dependent mul and add instructions with one - muladd.
The source code:

#include <immintrin.h>

__m128d simple_test(__m128d a, __m128d b, __m128d c, __m128d d) {
	__m128d temp = a * b;
	d = temp + c;
	return d;
}

LLVM MIR code before applying the pass:

body:             |
  bb.0.entry:
    liveins: $xmm0, $xmm1, $xmm2
  
    renamable $xmm0 = nofpexcept MULPDrr killed renamable $xmm0, killed renamable $xmm1, implicit $mxcsr
    renamable $xmm0 = nofpexcept ADDPDrr killed renamable $xmm0, killed renamable $xmm2, implicit $mxcsr
    RET64 $xmm0

LLVM MIR code after applying the pass:

body:             |
  bb.0.entry:
    liveins: $xmm0, $xmm1, $xmm2
  
    $xmm0 = VFMADD213PDr $xmm0, $xmm1, $xmm2, implicit $mxcsr
    RET64 $xmm0

@@ -23,6 +23,7 @@ tablegen(LLVM X86GenFoldTables.inc -gen-x86-fold-tables -asmwriternum=1)
add_public_tablegen_target(X86CommonTableGen)

set(sources
X86VolodinEMulAddPass.cpp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rewrite it as shared lib plugin.

Comment on lines 41 to 44
if (result == end(MIvector))
return false;
else
return true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (result == end(MIvector))
return false;
else
return true;
return (result != end(MIvector));


for (MachineBasicBlock &MBB : MF) {
for (auto iterator = MBB.begin(); iterator != MBB.end(); ++iterator) {
if (iterator->getOpcode() == X86::MULPDrr) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (iterator->getOpcode() == X86::MULPDrr) {
if (iterator->getOpcode() != X86::MULPDrr) {
continue;
}

# e = a + c;
# return d - e;
# }

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add also:

# __m128d another_test(__m128d a, __m128d b, __m128d c, __m128d d) {
# 	__m128d t = a * b;
# 	__m128d t2 = c * d;
# 	t2 = t + t2;
# 	t = t + c;
# 	return t * t2;
# }

@evldn
Copy link
Author

evldn commented Apr 26, 2024

  1. I rewrote pass as shared lib plugin.
  2. I added the test you suggested, which was performed incorrectly on the old version of the pass. I fixed this by adding additional checks to the pass that track the mutability of operands between the mul and add instructions.

@m-ly4 m-ly4 merged commit 70b2040 into NN-complr-tech:course-spring-2024 Apr 26, 2024
5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants