Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant expressions in LLVM code #44113

Closed
alexeyr mannequin opened this issue Feb 4, 2020 · 28 comments
Closed

Redundant expressions in LLVM code #44113

alexeyr mannequin opened this issue Feb 4, 2020 · 28 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@alexeyr
Copy link
Mannequin

alexeyr mannequin commented Feb 4, 2020

Bugzilla Link 44768
Resolution FIXED
Resolved on Oct 12, 2021 09:46
Version trunk
OS Windows NT
Blocks #51462
CC @asb,@chmeeedalf,@topperc,@davidbolvansky,@RKSimon,@Meinersbur,@tobiasgrosser
Fixed by commit(s) rGb8dc54cf39b,rG83d0db59d6ff,rG17785cc7a105

Extended Description

When running my expanded version of misc-redundant-expression on LLVM source, following potential problems were found (after filtering false positives):

llvm/utils/TableGen/CodeGenDAGPatterns.cpp:483:35: warning: both sides of operator are equivalent [misc-redundant-expression]
if (any_of(S, isIntegerOrPtr) && any_of(S, isIntegerOrPtr)) {
^
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:3875:34: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]
return UseSPE ? PPC::PRED_LE : PPC::PRED_LE;
^
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:3878:34: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]
return UseSPE ? PPC::PRED_GT : PPC::PRED_GT;
^
polly/lib/Support/ISLTools.cpp:67:23: warning: both sides of operator are equivalent [misc-redundant-expression]
for (auto i = Dims1 - Dims1; i < Dims1; i += 1)
^
polly/lib/Support/ISLTools.cpp:69:23: warning: both sides of operator are equivalent [misc-redundant-expression]
for (auto i = Dims2 - Dims2; i < Dims2; i += 1) {
^
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp:175:79: warning: Operator has equivalent nested operands [misc-redundant-expression]
Config.DiscardMode != DiscardType::None || !Config.SymbolsToAdd.empty() ||
^
(the last one repeats Config.StripNonAlloc and Config.StripSections twice)

These can probably remain, but I am not sure:

clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp:45:17: warning: expression is redundant [misc-redundant-expression]
if (TokKind == tok::NUM_TOKENS || TokKind != tok::comment)
^
llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp:122:24: warning: expression is redundant [misc-redundant-expression]
assert(TiedToIndex == -1 ||
^

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 4, 2020

When running my expanded version of misc-redundant-expression on LLVM
source, following potential problems were found (after filtering false
positives):

llvm/utils/TableGen/CodeGenDAGPatterns.cpp:483:35: warning: both sides of
operator are equivalent [misc-redundant-expression]
if (any_of(S, isIntegerOrPtr) && any_of(S, isIntegerOrPtr)) {

This was attempted at https://reviews.llvm.org/D69741 but hit issues with it causing timeouts on some buildbots that were never resolved.

@davidbolvansky
Copy link
Collaborator

RISC V backend causes build problems if we fix this code :(

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 4, 2020

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:3875:34: warning: 'true' and
'false' expressions are equivalent [misc-redundant-expression]
return UseSPE ? PPC::PRED_LE : PPC::PRED_LE;
^
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:3878:34: warning: 'true' and
'false' expressions are equivalent [misc-redundant-expression]
return UseSPE ? PPC::PRED_GT : PPC::PRED_GT;

Justin - these duplicates were added at rG2c4620ad57b8 - please can you take a look?

@chmeeedalf
Copy link
Contributor

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:3875:34: warning: 'true' and
'false' expressions are equivalent [misc-redundant-expression]
return UseSPE ? PPC::PRED_LE : PPC::PRED_LE;
^
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:3878:34: warning: 'true' and
'false' expressions are equivalent [misc-redundant-expression]
return UseSPE ? PPC::PRED_GT : PPC::PRED_GT;

Justin - these duplicates were added at rG2c4620ad57b8 - please can you take
a look?

Obvious redundancy is obviously redundant. That set of changes was pretty mechanical. I'll remove the redundancies.

@chmeeedalf
Copy link
Contributor

Reset for someone else to take the non-SPE redundancies.

@chmeeedalf
Copy link
Contributor

PowerPC bit was fixed in rGb8dc54cf39b

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 4, 2020

llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp:122:24: warning: expression
is redundant [misc-redundant-expression]
assert(TiedToIndex == -1 ||

Fixed in rG83d0db59d6ff

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 4, 2020

clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp:45:
17: warning: expression is redundant [misc-redundant-expression]
if (TokKind == tok::NUM_TOKENS || TokKind != tok::comment)

Fixed in rG17785cc7a105

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 4, 2020

                             ^

polly/lib/Support/ISLTools.cpp:67:23: warning: both sides of operator are
equivalent [misc-redundant-expression]
for (auto i = Dims1 - Dims1; i < Dims1; i += 1)
^
polly/lib/Support/ISLTools.cpp:69:23: warning: both sides of operator are
equivalent [misc-redundant-expression]
for (auto i = Dims2 - Dims2; i < Dims2; i += 1) {

Tobias - please would you be able to deal with these?

@tobiasgrosser
Copy link
Contributor

AFAIK the initial values should be zero both times. Michael Kruse wrote the code initially. @​Michael, do you recall why there are these surprising differences?

Btw., Alex, this is a great new warning. Thanks for pointing it out.

@Meinersbur
Copy link
Member

Fixed in https://reviews.llvm.org/rG84c934a5cbe2fdb7e0bb61a94e4dfa5e6cc3e0b2

The idiom

for (auto i = n - n; i < n; i += 1)

was intended to automatically derive the type of i from n (signed/unsigned int) and avoid the 'mixed signed/unsigned comparison' warning. However, almost-always-auto was never used in the LLVM coding style (although we used it in Polly for some time) and I did never intended to use this idiom upstream.

@tobiasgrosser
Copy link
Contributor

Thanks Michael

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 10, 2020

When running my expanded version of misc-redundant-expression on LLVM
source, following potential problems were found (after filtering false
positives):

llvm/utils/TableGen/CodeGenDAGPatterns.cpp:483:35: warning: both sides of
operator are equivalent [misc-redundant-expression]
if (any_of(S, isIntegerOrPtr) && any_of(S, isIntegerOrPtr)) {

Reopened, we still need to fix this (annoying) one.

@RKSimon
Copy link
Collaborator

RKSimon commented Aug 7, 2020

*** Bug llvm/llvm-bugzilla-archive#47032 has been marked as a duplicate of this bug. ***

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 26, 2020

The first redundancy is a bug, is it not?

llvm/utils/TableGen/CodeGenDAGPatterns.cpp:483:35: warning: both sides of operator are equivalent [misc-redundant-expression]
if (any_of(S, isIntegerOrPtr) && any_of(S, isIntegerOrPtr)) {
^
The second any_of() should be testing B.

@davidbolvansky
Copy link
Collaborator

Yes, bug. But if you fix it, riscv backend will break.

@RKSimon
Copy link
Collaborator

RKSimon commented Dec 26, 2020

Yes, bug. But if you fix it, riscv backend will break.

https://reviews.llvm.org/D69741 tried to fix it but RISCV then exploded :-(

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 26, 2020

Is it worth trying to investigate what's going on? If not, I could at least remove the redundant test and add a comment.

@RKSimon
Copy link
Collaborator

RKSimon commented Dec 26, 2020

Is it worth trying to investigate what's going on? If not, I could at least
remove the redundant test and add a comment.

I'd much prefer to see this fixed rather than dodged. The issue appeared to be a RISCV sext_inreg patterns not matching properly - D69741 has more details.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 26, 2020

Okay, I'll take a look.

@topperc
Copy link
Collaborator

topperc commented Dec 26, 2020

This seems to be an issue with HwModes. The patterns that are failing are RV64 only patterns. I think the hangs are occuring while trying to solve for RV32 mode where they have no solution.

@topperc
Copy link
Collaborator

topperc commented Dec 27, 2020

Patch
This patch appears to fix the hang and passes check-llvm. I did not check the effect on any generated files.

The basic idea is to suppress the change detection on small when small came from a temporary VT list rather than a real operand. Since we always create a new temporary VT list, we'll keep clearing it over and over again. If that keeps getting reported as a change we'll never terminate.

@davidbolvansky
Copy link
Collaborator

Craig - what is the status of your proposed patch?

@topperc
Copy link
Collaborator

topperc commented Oct 10, 2021

Copied to phab here https://reviews.llvm.org/D111502

@topperc
Copy link
Collaborator

topperc commented Oct 12, 2021

The CodeGenDAGPatterns.cpp redundancy has been fixed in aefaf16

Is anything else still open here?

@RKSimon
Copy link
Collaborator

RKSimon commented Oct 12, 2021

Resolving - all the other expressions had already been addressed. Thanks Craig!

@RKSimon
Copy link
Collaborator

RKSimon commented Nov 27, 2021

mentioned in issue llvm/llvm-bugzilla-archive#47032

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 27, 2021

mentioned in issue #51462

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

7 participants