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

            Bug ID: 37211
           Summary: [IndVarSimplify]  wrong code
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: pauls...@linux.vnet.ibm.com
                CC: llvm-bugs@lists.llvm.org

Created attachment 20212
  --> https://bugs.llvm.org/attachment.cgi?id=20212&action=edit
reduced testcase

This loop:

lbl_1806:                                         ; preds = %lbl_1806, %entry
 %d.0 = phi i16 [ 0, %entry ], [ %dec, %lbl_1806 ]
 %dec = add i16 %d.0, -1
 %conv2 = mul i16 %dec, %dec
 %tobool = icmp eq i16 %conv2, 0
 br i1 %tobool, label %if.end, label %lbl_1806

if.end:                                           ; preds = %lbl_1806
 %dec.lcssa = phi i16 [ %dec, %lbl_1806 ]
 %conv2.lcssa = phi i16 [ %conv2, %lbl_1806 ]
 %conv = sext i16 %dec.lcssa to i32

->  *** IR Dump After Induction Variable Simplification ***

; Loop:
lbl_1806:                                         ; preds = %lbl_1806, %entry
  %d.0 = phi i16 [ 0, %entry ], [ %dec, %lbl_1806 ]
   %dec = add i16 %d.0, -1
   %conv2 = mul i16 %dec, %dec
   %tobool = icmp eq i16 %conv2, 0
   br i1 %tobool, label %if.end, label %lbl_1806

; Exit blocks
if.end:                                           ; preds = %lbl_1806
  %conv = sext i16 0 to i32


After the loop, %conv is now sext of constant 0 instead of %dec. My guess is
that IndVarSimplify has thought that the loop must exit when 'mul i16
%dec, %dec' is 0, so therefore %dec is always zero after the loop.  However,
since %dec is i16, this happens also when it is -256, and 0 is therefore not
the correct constant after the loop in this case.

bin/clang -w -O3 -march=z13 ./wrong0.i -o ./a.out

Note: this disappears with '-mllvm -disable-licm-promotion'

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to