LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47858 - Missed simplification with not
Summary: Missed simplification with not
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-15 05:56 PDT by David Bolvansky
Modified: 2020-10-25 10:04 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s): e77ba263fe0e


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Bolvansky 2020-10-15 05:56:00 PDT
void foo(void);                                                                         
                                                                                                 
void s(unsigned a, unsigned b)                                                                                  
{                                                                                                
        unsigned x = ~b;                                                                           
                                                                                                 
        if (x > 0 && x > a)                                                                             
                foo();                                                                  
}

Clang -O3:

s(unsigned int, unsigned int):                                 # @s(unsigned int, unsigned int)
        cmp     esi, -1
        je      .LBB0_2
        not     esi
        cmp     esi, edi
        jbe     .LBB0_2
        jmp     foo()                         # TAILCALL
.LBB0_2:
        ret


GCC -O3:
s(unsigned int, unsigned int):
        not     esi
        cmp     esi, edi
        ja      .L4
        ret
.L4:
        jmp     foo()
Comment 1 Sanjay Patel 2020-10-20 06:30:37 PDT
define i1 @src(i32 %a, i32 %b) {
  %neg = xor i32 %b, -1
  %cmp.not = icmp ne i32 %b, -1
  %cmp1 = icmp ugt i32 %neg, %a
  %r = and i1 %cmp.not, %cmp1
  ret i1 %r
}

define i1 @tgt(i32 %a, i32 %b) {
  %neg = xor i32 %b, -1
  %cmp1 = icmp ugt i32 %neg, %a
  ret i1 %cmp1
}

-------------------------------------------------------------------------

Logic-of-icmps - we probably want a generalization that matches a negated operand on 1 side and a signed or unsigned limit constant on the other.
Comment 2 Sanjay Patel 2020-10-25 10:04:29 PDT
Should be fixed with:
https://reviews.llvm.org/rGe77ba263fe0e