[PATCH] D128123: [SDAG] try to replace subtract-from-constant with xor
Bjorn Pettersson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 11 15:16:46 PDT 2022
bjope added a comment.
Not sure really if this ends up as a regression or not, but with this source we can see some differences if for example using heaxagon or systemz as targets.
(This example is related to doing sub->xor in instcombine so not exactly the patch in this review.)
Input C program (sub_xor.c):
static unsigned ARR[100];
extern void populate(unsigned*);
unsigned foo(unsigned *a) {
populate(ARR);
unsigned sum = 0;
for (int j = 1; j < 4; ++j) {
unsigned *ptr = &ARR[99];
for (int i = 0; i < 70; ++i) {
sum += j * *(ptr - i);
}
}
return sum;
}
Compile with `clang -target hexagon -O2 sub_xor.c -o sub_xor.ll -emit-llvm -S` and the only difference will be some sub:s ending up as xor (depending on if the instcombine transform from commit 79bb915fb60b2cd2 <https://reviews.llvm.org/rG79bb915fb60b2cd220d89e3bb54f67abb8cdb7bd> is reverted or not).
If also comparing the result of `llc -O2 sub_xor.ll -o - -print-after-all`, given those two different versions of sub_xor.ll from prior step, we can see that Loop Strength Reduce can eliminate the sub but it does not eliminate the xor.
Well, this is the best in-tree example I got so far (when aiming at having a full test from C code, I guess this could be reduced to a much smaller test just running LSR to show that we get different result for sub vs xor).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128123/new/
https://reviews.llvm.org/D128123
More information about the llvm-commits
mailing list