Issue 124542
Summary [InstCombiner] WRONG code, InstCombiner suspected
Labels
Assignees
Reporter JonPsson1
    Bisect:
f044564db1cbc588d0cad4f953d38f6c787dadd4 is the first bad commit

commit f044564 "[InstCombine] Make backedge check in op of phi transform more precise (#106075)"

clang -march=z15 -O1 wrong0.i
[wrong0.tar.gz](https://github.com/user-attachments/files/18558277/wrong0.tar.gz)

I could not revert this commit cleanly on main, unfortunately - the diff below is between f044564^ <> f044564.

It looks to me that the inserted constant in the PHI should be 1 and not 0, or?:

```
cond.end: ; preds = %cond.false, %      cond.end: ; preds = %cond.false, %
  %cond = phi i64 [ %1, %cond.true ], [ %div, %cond.false ]                       %cond = phi i64 [ %1, %cond.true ], [ %div, %cond.false ]
  store i64 %cond, ptr @func_34___trans_tmp_29, align 8, !tbaa !11                store i64 %cond, ptr @func_34___trans_tmp_29, align 8, !tbaa !11
  %3 = load ptr, ptr @g_77, align 8, !tbaa !13                                    %3 = load ptr, ptr @g_77, align 8, !tbaa !13
  %4 = load i32, ptr %3, align 4, !tbaa !4 %4 = load i32, ptr %3, align 4, !tbaa !4
 %conv9 = trunc i32 %p_37 to i8 %conv9 = trunc i32 %p_37 to i8
  %cmp.i = icmp eq i8 %conv9, 1 %cmp.i = icmp eq i8 %conv9, 1
 %conv1.i = zext i1 %cmp.i to i32                                          <
 br i1 %cmp.i, label %safe_mod_func_uint8_t_u_u.exit, label %cond.false.i br i1 %cmp.i, label %safe_mod_func_uint8_t_u_u.exit, label %cond.false.i

cond.false.i:                                     ; preds = %cond.end           cond.false.i:                                     ; preds = %cond.end
  %conv8 = trunc i32 %4 to i8 %conv8 = trunc i32 %4 to i8
  %5 = urem i8 %conv8, %conv9 %5 = urem i8 %conv8, %conv9
  %rem.i = zext i8 %5 to i32 |     %6 = icmp ugt i8 %5, 1
 >     %7 = zext i1 %6 to i32
  br label %safe_mod_func_uint8_t_u_u.exit                                        br label %safe_mod_func_uint8_t_u_u.exit

safe_mod_func_uint8_t_u_u.exit: ; preds = %cond.end, %co      safe_mod_func_uint8_t_u_u.exit: ; preds = %cond.end, %co
  %cond.i = phi i32 [ %rem.i, %cond.false.i ], [ %conv1.i, %cond.end ]      |     %cond.i = phi i32 [ %7, %cond.false.i ], [ 0, %cond.end ]
  %cmp10 = icmp ugt i32 %cond.i, 1 |     %or = or i32 %4, %cond.i
  %conv11 = zext i1 %cmp10 to i32                                           <
  %or = or i32 %4, %conv11                                                  <
  store i32 %or, ptr %3, align 4, !tbaa !4 store i32 %or, ptr %3, align 4, !tbaa !4
  %6 = load i32, ptr @safe_mul_func_uint32_t_u_u_ui1, align 4, !tbaa !4     |     %8 = load i32, ptr @safe_mul_func_uint32_t_u_u_ui1, align 4, !tbaa !4
  %idxprom = sext i32 %p_36.3 to i64                                              %idxprom = sext i32 %p_36.3 to i64
  %arrayidx = getelementptr inbounds [7 x i32], ptr @g_95, i64 0, i64 %idx        %arrayidx = getelementptr inbounds [7 x i32], ptr @g_95, i64 0, i64 %idx
  %7 = load i32, ptr %arrayidx, align 4, !tbaa !4 |     %9 = load i32, ptr %arrayidx, align 4, !tbaa !4
  %dec = add nsw i32 %7, -1 |     %dec = add nsw i32 %9, -1
  store i32 %dec, ptr %arrayidx, align 4, !tbaa !4                                store i32 %dec, ptr %arrayidx, align 4, !tbaa !4
  %mul = mul nsw i32 %6, %7 |     %mul = mul nsw i32 %8, %9
  %conv12 = trunc i32 %mul to i8 %conv12 = trunc i32 %mul to i8
  store i8 %conv12, ptr @g_185_1, align 1, !tbaa !8 store i8 %conv12, ptr @g_185_1, align 1, !tbaa !8
  store i8 %conv12, ptr getelementptr inbounds (i8, ptr @g_255, i64 12), a        store i8 %conv12, ptr getelementptr inbounds (i8, ptr @g_255, i64 12), a
 %tobool16.not = icmp eq i32 %p_36.3, 0 %tobool16.not = icmp eq i32 %p_36.3, 0
  %tobool19.not = icmp eq i32 %p_37, 0                                            %tobool19.not = icmp eq i32 %p_37, 0
  %.47 = select i1 %tobool19.not, i32 0, i32 11 %.47 = select i1 %tobool19.not, i32 0, i32 11
  %8 = or i32 %p_36.3, %p_37                                                |     %10 = or i32 %p_36.3, %p_37
  %cond37 = icmp eq i32 %8, 0 |     %cond37 = icmp eq i32 %10, 0
 %cleanup.dest.slot.0 = select i1 %tobool16.not, i32 %.47, i32 9 %cleanup.dest.slot.0 = select i1 %tobool16.not, i32 %.47, i32 9
  br i1 %cond37, label %cleanup.cont, label %cleanup22                            br i1 %cond37, label %cleanup.cont, label %cleanup22


```

@nikic 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to