[llvm-bugs] [Bug 43210] New: [SimplifyCFG] Failure to flatten and simplify checks
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Tue Sep  3 10:43:22 PDT 2019
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=43210
            Bug ID: 43210
           Summary: [SimplifyCFG] Failure to flatten and simplify checks
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org
https://godbolt.org/z/rokl2m
#include <cstdint> // for intptr_t
bool is_ub(char *base, unsigned long offset) {
  // Cast pointer to integer, perform usual arithmetic addition,
  // and cast to pointer. This is legal.
  char *computed = reinterpret_cast<char*>(reinterpret_cast<intptr_t>(base) +
offset);
  // If either the pointer becomes non-nullptr, or becomes nullptr, we must use
``computed`` result.
  return (((base == nullptr) && (computed != nullptr)) ||
          ((base != nullptr) && (computed == nullptr)));
}
After -O3 produces:
define dso_local zeroext i1 @_Z5is_ubPcm(i8* %0, i64 %1) local_unnamed_addr #0
{
  %3 = ptrtoint i8* %0 to i64
  %4 = add i64 %3, %1
  %5 = icmp eq i8* %0, null
  %6 = icmp ne i64 %4, 0
  %7 = and i1 %5, %6
  br i1 %7, label %12, label %8
8:                                                ; preds = %2
  %9 = icmp ne i8* %0, null
  %10 = icmp eq i64 %4, 0
  %11 = and i1 %9, %10
  br label %12
12:                                               ; preds = %8, %2
  %13 = phi i1 [ true, %2 ], [ %11, %8 ]
  ret i1 %13
}
But this should just be
define dso_local zeroext i1 @_Z5is_ubPcm(i8* %0, i64 %1) local_unnamed_addr #0
{
  %3 = ptrtoint i8* %0 to i64
  %4 = icmp ne i8* %0, null
  %5 = sub i64 0, %1
  %6 = icmp eq i64 %3, %5
  %7 = xor i1 %4, %6
  ret i1 %7
}
-- 
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/20190903/f05a6060/attachment.html>
    
    
More information about the llvm-bugs
mailing list