8000 fold shifts through constant or by can-lehmann · Pull Request #145 · can-lehmann/metajit.cpp · GitHub
[go: up one dir, main page]

Skip to content

fold shifts through constant or - #145

Open
can-lehmann wants to merge 2 commits into
mainfrom
can-shift-through-constant-or
Open

can-lehmann wants to merge 2 commits into
mainfrom
can-shift-through-constant-or

Conversation

@can-lehmann
Copy link
Copy Markdown
Owner

No description provided.

8000 @github-actions
Copy link
Copy Markdown

Coverage

File Lines Functions Branches
bitprovenance.hpp 🟢 100.00% 🟢 100.00% 🟡 82.13%
genext.hpp 🟡 71.23% 🟡 86.89% 🟡 72.56%
jitir.hpp 🟡 72.96% 🟡 79.45% 🟡 71.77%
jitir_llvmapi.hpp 🔴 54.74% 🟡 80.00% 🔴 50.00%
llvmgen.hpp 🟢 90.80% 🟢 90.00% 🟡 82.02%
lowerllvm.hpp 🔴 69.57% 🟡 87.50% 🔴 50.49%
x86gen.hpp 🟢 90.25% 🟡 86.93% 🟡 84.67%
x86insts.inc.hpp 🟡 84.76% - -
TOTAL 🟡 75.80% 🟡 81.62% 🟡 76.54%
Diff Coverage

Diff Coverage

Diff: origin/main...HEAD, staged and unstaged changes

  • jitir.hpp (50.0%): Missing lines 4314,8030-8033,8039-8049

Summary

  • Total: 32 lines
  • Missing: 16 lines
  • Coverage: 50%

jitir.hpp

Lines 4310-4318

  4310             uint64_t combined = inner_constant->value() | constant->value();
  4311             if (combined == inner_constant->value()) {
  4312               return inner;
  4313             }
! 4314             return fold_or(inner->arg(0), build_const(a->type(), combined));
  4315           }
  4316         }
  4317       } else if (dynmatch(AndInst, and_a, a)) {
  4318         if (dynmatch(AndInst, and_b, b)) {

Lines 8026-8037

  8026               if ((used.used & b->value()) == 0) {
  8027                 return or_inst->arg(0);
  8028               }
  8029               if (dynmatch(OrInst, inner, or_inst->arg(0))) {
! 8030                 if (dynamic_cast<Const*>(inner->arg(1))) {
! 8031                   return _builder.fold_or(inner, b);
! 8032                 }
! 8033               }
  8034             }
  8035           } else if (dynmatch(ShlInst, shl, inst)) {
  8036             if (dynmatch(Const, shift, shl->arg(1))) {
  8037               if (shift->value() < type_width(shl->type())) {

Lines 8035-8053

  8035           } else if (dynmatch(ShlInst, shl, inst)) {
  8036             if (dynmatch(Const, shift, shl->arg(1))) {
  8037               if (shift->value() < type_width(shl->type())) {
  8038                 if (dynmatch(OrInst, inner, shl->arg(0))) {
! 8039                   if (inner->name() < section->name_count() && uses.at(inner).size() == 1 &&
! 8040                       uses.at(inner).front().inst == shl) {
! 8041                     for (size_t index = 0; index < 2; index++) {
! 8042                       if (dynmatch(Const, constant, inner->arg(index))) {
! 8043                         uint64_t shifted = (constant->value() << shift->value()) & type_mask(shl->type());
! 8044                         return _builder.fold_or(_builder.fold_shl(inner->arg(1 - index), shift),
! 8045                                                 _builder.build_const(shl->type(), shifted));
! 8046                       }
! 8047                     }
! 8048                   }
! 8049                 }
  8050               }
  8051             }
  8052           } else if (dynamic_cast<ResizeUInst*>(inst) ||
  8053                      dynamic_cast<ResizeSInst*>(inst)) {

@github-actions
Copy link
Copy Markdown

Coverage

File Lines Functions Branches
bitprovenance.hpp 🟢 100.00% 🟢 100.00% 🟡 82.13%
genext.hpp 🟡 71.23% 🟡 86.89% 🟡 72.56%
jitir.hpp 🟡 72.96% 🟡 79.45% 🟡 71.77%
jitir_llvmapi.hpp 🔴 54.74% 🟡 80.00% 🔴 50.00%
llvmgen.hpp 🟢 90.80% 🟢 90.00% 🟡 82.02%
lowerllvm.hpp 🔴 69.57% 🟡 87.50% 🔴 50.49%
x86gen.hpp 🟢 90.25% 🟡 86.93% 🟡 84.67%
x86insts.inc.hpp 🟡 84.76% - -
TOTAL 🟡 75.80% 🟡 81.62% 🟡 76.54%
Diff Coverage

Diff Coverage

Diff: origin/main...HEAD, staged and unstaged changes

  • jitir.hpp (50.0%): Missing lines 4315,8031,8033-8035,8041-8044,8046-8052

Summary

  • Total: 32 lines
  • Missing: 16 lines
  • Coverage: 50%

jitir.hpp

Lines 4311-4319

  4311             uint64_t combined = inner_constant->value() | constant->value();
  4312             if (combined == inner_constant->value()) {
  4313               return inner;
  4314             }
! 4315             return fold_or(inner->arg(0), build_const(a->type(), combined));
  4316           }
  4317         }
  4318       } else if (dynmatch(AndInst, and_a, a)) {
  4319         if (dynmatch(AndInst, and_b, b)) {

Lines 8027-8039

  8027               if ((used.used & b->value()) == 0) {
  8028                 return or_inst->arg(0);
  8029               }
  8030               if (dynmatch(OrInst, inner, or_inst->arg(0))) {
! 8031                 if (dynamic_cast<Const*>(inner->arg(1))) {
  8032                   // (x | c1) | c2 => x | (c1 | c2)
! 8033                   return _builder.fold_or(inner, b);
! 8034                 }
! 8035               }
  8036             }
  8037           } else if (dynmatch(ShlInst, shl, inst)) {
  8038             if (dynmatch(Const, shift, shl->arg(1))) {
  8039               if (shift->value() < type_width(shl->type())) {

Lines 8037-8056

  8037           } else if (dynmatch(ShlInst, shl, inst)) {
  8038             if (dynmatch(Const, shift, shl->arg(1))) {
  8039               if (shift->value() < type_width(shl->type())) {
  8040                 if (dynmatch(OrInst, inner, shl->arg(0))) {
! 8041                   if (inner->name() < section->name_count() && uses.at(inner).size() == 1 &&
! 8042                       uses.at(inner).front().inst == shl) {
! 8043                     for (size_t index = 0; index < 2; index++) {
! 8044                       if (dynmatch(Const, constant, inner->arg(index))) {
  8045                         // (x | c) << k => (x << k) | ((c << k) & type_mask), for single-use OR and k < width
! 8046                         uint64_t shifted = (constant->value() << shift->value()) & type_mask(shl->type());
! 8047                         return _builder.fold_or(_builder.fold_shl(inner->arg(1 - index), shift),
! 8048                                                 _builder.build_const(shl->type(), shifted));
! 8049                       }
! 8050                     }
! 8051                   }
! 8052                 }
  8053               }
  8054             }
  8055           } else if (dynamic_cast<ResizeUInst*>(inst) ||
  8056                      dynamic_cast<ResizeSInst*>(inst)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0