[LLVMbugs] [Bug 14955] New: Failure to remove no-op zext, shl, and, or, trunc chain

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jan 14 14:05:43 PST 2013


             Bug #: 14955
           Summary: Failure to remove no-op zext,shl,and,or,trunc chain
           Product: tools
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: opt
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 9873
  --> http://llvm.org/bugs/attachment.cgi?id=9873
Benchmark of sentinel-based iterators

The following module fails to optimize with `opt -O3`:

define void @_Z10copy_rangeI13SentinelRangeIPKcEPcEvOT_T0_(i8* nocapture
%sentinel_.i.i, i8* nocapture %tmp, i8* nocapture %dest) nounwind uwtable
noinline ssp {
  %tmp1 = load i8* %sentinel_.i.i, align 1, !tbaa !0
  %tmp2 = load i8* %tmp, align 1, !tbaa !0
  %cmp.i.i.i.i = icmp eq i8 %tmp2, %tmp1
  br i1 %cmp.i.i.i.i, label %for.end, label %for.body.lr.ph

for.body.lr.ph:                                   ; preds = %entry
  %retval.sroa.1.8.insert.ext.i.i = zext i8 %tmp1 to i64
  br label %for.body

for.body:                                         ; preds = %for.body,
  %tmp3 = phi i8 [ %tmp2, %for.body.lr.ph ], [ %tmp4, %for.body ]
  %dest.addr.014 = phi i8* [ %dest, %for.body.lr.ph ], [ %incdec.ptr, %for.body
  %first.sroa.0.0.load8913 = phi i8* [ %tmp, %for.body.lr.ph ], [
%incdec.ptr.i, %for.body ]
  %first.sroa.1.9.load1012 = phi i64 [ %retval.sroa.1.8.insert.ext.i.i,
%for.body.lr.ph ], [ %first.sroa.1.9.insert.insert, %for.body ]
  %incdec.ptr = getelementptr inbounds i8* %dest.addr.014, i64 1
  store i8 %tmp3, i8* %dest.addr.014, align 1, !tbaa !0
  %incdec.ptr.i = getelementptr inbounds i8* %first.sroa.0.0.load8913, i64 1
  %tmp4 = load i8* %incdec.ptr.i, align 1, !tbaa !0
  %first.sroa.1.8.extract.trunc = trunc i64 %first.sroa.1.9.load1012 to i8
  %cmp.i = icmp eq i8 %tmp4, %first.sroa.1.8.extract.trunc
  %first.sroa.1.9.insert.ext = zext i1 %cmp.i to i64
  %first.sroa.1.9.insert.shift = shl nuw nsw i64 %first.sroa.1.9.insert.ext, 8
  %first.sroa.1.9.insert.mask = and i64 %first.sroa.1.9.load1012, -65281
  %first.sroa.1.9.insert.insert = or i64 %first.sroa.1.9.insert.shift,
  br i1 %cmp.i, label %for.end, label %for.body

for.end:                                          ; preds = %for.body, %entry
  ret void
!0 = metadata !{metadata !"omnipotent char", metadata !1}
!1 = metadata !{metadata !"Simple C/C++ TBAA"}

%cmp.i is an i1, which must be 0 for the %for.body loop to continue. If it's 0,
%first.sroa.1.9.insert.ext is 0, so %first.sroa.1.9.insert.shift is 0.
%first.sroa.1.9.load1012 was a zext'ed i8, and -65281 is 0xffffffffffff00ff, so
%first.sroa.1.9.insert.mask == %first.sroa.1.9.load1012. That means
%first.sroa.1.9.insert.insert == %first.sroa.1.9.load1012 ==
%retval.sroa.1.8.insert.ext.i.i, so there's no need to update it across the

I've attached the original C++ code, which I compiled using `clang++ -std=c++11
-stdlib=libc++ -O2 test2.cc -S -emit-llvm -o -` on OSX 10.8.2

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list