[llvm-bugs] [Bug 35906] New: Comparisons against last enum are optimizable (found via LLVM classof() analysis)
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 11 05:21:37 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=35906
Bug ID: 35906
Summary: Comparisons against last enum are optimizable (found
via LLVM classof() analysis)
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: dave at znu.io
CC: llvm-bugs at lists.llvm.org
In LLVM and derived projects, exhaustive enums are common. For example, from
the casting machinery, an abstract class might have code roughly like this:
static bool classof(Thing *t) {
return t->getKind() >= ThingKind::First_AbstractFoo &&
t->getKind() <= ThingKind::Last_AbstractFoo;
}
If ThingKind::Last_AbstractFoo equals the last enumeration, then "t->getKind()
<= ThingKind::Last_AbstractFoo" will always be true. (Similarly, "t->getKind()
> ThingKind::Last_AbstractFoo" will always fail). That being said, clang
generates the IR for the pointless comparison above.
This seems like an easy optimization opportunity.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180111/76bc1d1f/attachment.html>
More information about the llvm-bugs
mailing list