Skip to content

Commit 015ab4e

Browse files
committed
[Reassociate] Allow implicit truncation when converting adds to mul
It's okay if the number of adds overflows. Explicitly allow implicit truncation.
1 parent 42a47bf commit 015ab4e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,11 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
15131513

15141514
// Insert a new multiply.
15151515
Type *Ty = TheOp->getType();
1516-
Constant *C = Ty->isIntOrIntVectorTy() ?
1517-
ConstantInt::get(Ty, NumFound) : ConstantFP::get(Ty, NumFound);
1516+
// Truncate if NumFound overflows the type.
1517+
Constant *C = Ty->isIntOrIntVectorTy()
1518+
? ConstantInt::get(Ty, NumFound, /*IsSigned=*/false,
1519+
/*ImplicitTrunc=*/true)
1520+
: ConstantFP::get(Ty, NumFound);
15181521
Instruction *Mul = CreateMul(TheOp, C, "factor", I->getIterator(), I);
15191522
Mul->setDebugLoc(I->getDebugLoc());
15201523

0 commit comments

Comments
 (0)