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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to