[llvm-bugs] [Bug 26430] New: Flatten two comparisons against a constant power of two into an OR + cmp
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Feb 1 18:59:09 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26430
Bug ID: 26430
Summary: Flatten two comparisons against a constant power of
two into an OR + cmp
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: listmail at philipreames.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Given an IR fragment like the following:
bb1:
%cmp1 = icmp ult i32 %a, 16
br i1 %cmp1, label %bb2, label %exit1 ;; rarely not taken
bb2:
%cmp2 = icmp ult i32 %b, 16
br i1 %cmp2, label %fallthrough, label %exit2 ;; rarely not taken
fallthrough:
...
We can rewrite this as:
bb1:
%or = or i32 %a, %b
%cmp1 = icmp ult i32 %or, 16
br i1 %cmp1, label %fallthrough, label %common_exit ;; rarely not taken
fallthrough:
...
common_exit:
%cmp2 = icmp ult i32 %a, 16
br i1 %cmp2, label %exit1, label %exit2 ;; rarely not taken
This transform is likely fairly target specific and produces IR which is hard
for other passes to analyse. Given that, it probably belongs fairly late. CGP
might be one reasonable place.
The general conditions under which this will apply are:
- Two successive tests against the same constant on different values
- The tests form what is essentially a bit test. i.e. ult for 2^X or ule for
2^X-1.
- The first branch fails rarely.
- No side effecting instructions in %bb2 and few total instructions (we end up
essentially speculating them)
--
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/20160202/f9244b47/attachment.html>
More information about the llvm-bugs
mailing list