DebugLoc Loc = Builder.GetInsertPoint()->getDebugLoc();
SCEVInsertPointGuard Guard(Builder, this);
- if (Opcode != Instruction::UDiv) {
+ auto *RHSConst = dyn_cast<ConstantInt>(RHS);
+
+ if (Opcode != Instruction::UDiv || (RHSConst && !RHSConst->isZero())) {
// FIXME: There is alredy similar logic in expandCodeFor, we should see if
// this is actually needed here.
ASSERT_NE(DivFromScratchExpansionInst, nullptr);
EXPECT_EQ(DivInst->getParent(), DivFromScratchExpansionInst->getParent());
}
+
+ {
+ auto *ArgY = getArgByName(F, "y");
+ auto *SafeDivSCEV =
+ SE.getUDivExpr(SE.getSCEV(ArgY), SE.getConstant(APInt(32, 19)));
+
+ auto *SafeDivExpansion =
+ Expander.expandCodeFor(SafeDivSCEV, SafeDivSCEV->getType(),
+ DivInst->getParent()->getTerminator());
+ auto *SafeDivExpansionInst = dyn_cast<Instruction>(SafeDivExpansion);
+ ASSERT_NE(SafeDivExpansionInst, nullptr);
+ EXPECT_EQ("loop.ph", SafeDivExpansionInst->getParent()->getName());
+ }
});
}