if (!DivDominates && !DT.dominates(RemInst, DivInst)) {
// We have matching div-rem pair, but they are in two different blocks,
// neither of which dominates one another.
- assert(!RemOriginallyWasInExpandedForm &&
- "Won't happen for expanded-form rem.");
// FIXME: We could hoist both ops to the common predecessor block?
continue;
}
%ret = phi i128 [ %rem, %if ], [ 3, %entry ]
ret i128 %ret
}
+
+; Even in expanded form, we can end up with div and rem in different basic
+; blocks neither of which dominates each another.
+define i32 @can_have_divrem_in_mutually_nondominating_bbs(i1 %cmp, i32 %a, i32 %b) {
+; CHECK-LABEL: @can_have_divrem_in_mutually_nondominating_bbs(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[CMP:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: [[T0:%.*]] = udiv i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[T1:%.*]] = mul nuw i32 [[T0]], [[B]]
+; CHECK-NEXT: [[T2_RECOMPOSED:%.*]] = urem i32 [[A]], [[B]]
+; CHECK-NEXT: br label [[END:%.*]]
+; CHECK: if.else:
+; CHECK-NEXT: [[T3:%.*]] = udiv i32 [[A]], [[B]]
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[RET:%.*]] = phi i32 [ [[T2_RECOMPOSED]], [[IF_THEN]] ], [ [[T3]], [[IF_ELSE]] ]
+; CHECK-NEXT: ret i32 [[RET]]
+;
+entry:
+ br i1 %cmp, label %if.then, label %if.else
+
+if.then:
+ %t0 = udiv i32 %a, %b
+ %t1 = mul nuw i32 %t0, %b
+ %t2 = sub i32 %a, %t1
+ br label %end
+
+if.else:
+ %t3 = udiv i32 %a, %b
+ br label %end
+
+end:
+ %ret = phi i32 [ %t2, %if.then ], [ %t3, %if.else ]
+ ret i32 %ret
+}