[PATCH] D71164: [InstCombine] Fix infinite loop due to bitcast <-> phi transforms

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 13:15:17 PST 2020


nikic added a comment.

I'm a bit stumped here. From the trace I see that previously instcombine produced

  ; Function Attrs: nounwind uwtable
  define dso_local { double, double } @Compute_Leaf(%struct.leaf* nocapture %l, double %pi_R, double %pi_I) local_unnamed_addr #0 {
  entry:
    %0 = bitcast %struct.leaf* %l to i64*
    %1 = load i64, i64* %0, align 8, !tbaa !32
    store i64 %1, i64* bitcast (double* @P to i64*), align 8, !tbaa !23
    %Q = getelementptr inbounds %struct.leaf, %struct.leaf* %l, i64 0, i32 0, i32 1
    %2 = bitcast double* %Q to i64*
    %3 = load i64, i64* %2, align 8, !tbaa !34
    store i64 %3, i64* bitcast (double* @Q to i64*), align 8, !tbaa !23
    tail call void @optimize_node(double %pi_R, double %pi_I)
    %4 = load double, double* @P, align 8, !tbaa !23
    %cmp = fcmp olt double %4, 0.000000e+00
    br i1 %cmp, label %if.then, label %entry.if.end_crit_edge
  
  entry.if.end_crit_edge:                           ; preds = %entry
    %.pre = load i64, i64* bitcast (double* @Q to i64*), align 8, !tbaa !23
    %5 = bitcast i64 %.pre to double
    %phitmp = bitcast i64 %.pre to double
    br label %if.end
  
  if.then:                                          ; preds = %entry
    store double 0.000000e+00, double* @P, align 8, !tbaa !23
    store double 0.000000e+00, double* @Q, align 8, !tbaa !23
    br label %if.end
  
  if.end:                                           ; preds = %entry.if.end_crit_edge, %if.then
    %6 = phi double [ 0.000000e+00, %if.then ], [ %5, %entry.if.end_crit_edge ]
    %7 = phi double [ 0.000000e+00, %if.then ], [ %phitmp, %entry.if.end_crit_edge ]
    %8 = phi double [ 0.000000e+00, %if.then ], [ %4, %entry.if.end_crit_edge ]
    %9 = phi double [ 0.000000e+00, %if.then ], [ %4, %entry.if.end_crit_edge ]
    %10 = getelementptr %struct.leaf, %struct.leaf* %l, i64 0, i32 0, i32 0
    store double %8, double* %10, align 8, !tbaa !32
    store double %6, double* %Q, align 8, !tbaa !34
    %.fca.0.insert = insertvalue { double, double } undef, double %9, 0
    %.fca.1.insert = insertvalue { double, double } %.fca.0.insert, double %7, 1
    ret { double, double } %.fca.1.insert
  }

while with this patch:

  ; Function Attrs: nounwind uwtable
  define dso_local { double, double } @Compute_Leaf(%struct.leaf* nocapture %l, double %pi_R, double %pi_I) local_unnamed_addr #0 {
  entry:
    %0 = bitcast %struct.leaf* %l to i64*
    %1 = load i64, i64* %0, align 8, !tbaa !32
    store i64 %1, i64* bitcast (double* @P to i64*), align 8, !tbaa !23
    %Q = getelementptr inbounds %struct.leaf, %struct.leaf* %l, i64 0, i32 0, i32 1
    %2 = bitcast double* %Q to i64*
    %3 = load i64, i64* %2, align 8, !tbaa !34
    store i64 %3, i64* bitcast (double* @Q to i64*), align 8, !tbaa !23
    tail call void @optimize_node(double %pi_R, double %pi_I)
    %4 = load double, double* @P, align 8, !tbaa !23
    %cmp = fcmp olt double %4, 0.000000e+00
    br i1 %cmp, label %if.then, label %entry.if.end_crit_edge
  
  entry.if.end_crit_edge:                           ; preds = %entry
    %.pre12 = load double, double* @Q, align 8, !tbaa !23
    br label %if.end
  
  if.then:                                          ; preds = %entry
    store double 0.000000e+00, double* @P, align 8, !tbaa !23
    store double 0.000000e+00, double* @Q, align 8, !tbaa !23
    br label %if.end
  
  if.end:                                           ; preds = %entry.if.end_crit_edge, %if.then
    %5 = phi double [ 0.000000e+00, %if.then ], [ %.pre12, %entry.if.end_crit_edge ]
    %6 = phi double [ 0.000000e+00, %if.then ], [ %4, %entry.if.end_crit_edge ]
    %7 = phi double [ 0.000000e+00, %if.then ], [ %4, %entry.if.end_crit_edge ]
    %8 = getelementptr %struct.leaf, %struct.leaf* %l, i64 0, i32 0, i32 0
    store double %6, double* %8, align 8, !tbaa !32
    store double %5, double* %Q, align 8, !tbaa !34
    %.fca.0.insert = insertvalue { double, double } undef, double %7, 0
    %.fca.1.insert = insertvalue { double, double } %.fca.0.insert, double 0.000000e+00, 1
    ret { double, double } %.fca.1.insert
  }

Note the `double 0.0` argument on the second insertvalue.

Unfortunately I've not been able to reproduce this when running `-instcombine` standalone. I've also tried adding `-tbaa -loops -expensive-combines` but that didn't work either.

Am I missing some option that makes opt different from clang O3 <https://reviews.llvm.org/owners/package/3/> instcombine?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71164/new/

https://reviews.llvm.org/D71164





More information about the llvm-commits mailing list