[llvm-bugs] [Bug 51265] New: Missed optimization on redundant condition

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 29 01:30:17 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51265

            Bug ID: 51265
           Summary: Missed optimization on redundant condition
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: zhongyunde at tom.com
                CC: llvm-bugs at lists.llvm.org

Missed optimization on redundant condition.

a) test base on gcc 7.3, it will generate same assemble with O3 if change
condtion 
 if (nex_group) into if (1)
b) while with the clang 12.0.1, even with the newest trunk version (commit
79fbbeb4), use  if (1) will generate more smarter code.

For example in x86-x64 clang (https://godbolt.org/z/zzWa1d4x1), use `test r10`
to check whether or not r10 is equal zero is redundant.

exclusion(int, int, int*):                       # @exclusion(int, int, int*)
        mov     r10d, dword ptr [rip + nex_group]
        xor     eax, eax
        test    r10, r10
        je      .LBB0_11
        test    r10d, r10d
        jle     .LBB0_11
        movsxd  r11, esi



Example code built with clang test.c -S -O3

// ===== test.c =========
int nex_group;
int *ex1_bit,*ex2_bit;

int exclusion(int i, int j, int *mask) {
  int m;

  // we can see that condition nex_group already guard in statement for
  if (nex_group) { // generate smarter assemble with if (1)
    for (m = 0; m < nex_group; m++) {
      if (mask[i] & ex1_bit[m] && mask[j] & ex2_bit[m]) return 1;
      if (mask[i] & ex2_bit[m] && mask[j] & ex1_bit[m]) return 1;
    }
  }

  return 0;
}

-- 
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/20210729/e5ef51ba/attachment.html>


More information about the llvm-bugs mailing list