Skip to content

Commit

Permalink
[ConstantRange] Optimize smul nowrap with constant (NFC)
Browse files Browse the repository at this point in the history
Don't call makeExactMulNSWRegion() twice with the same value.
  • Loading branch information
nikic committed Sep 15, 2023
1 parent 73371fa commit ab6667f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/IR/ConstantRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
if (Unsigned)
return makeExactMulNUWRegion(Other.getUnsignedMax());

// Avoid one makeExactMulNSWRegion() call for the common case of constants.
if (const APInt *C = Other.getSingleElement())
return makeExactMulNSWRegion(*C);

return makeExactMulNSWRegion(Other.getSignedMin())
.intersectWith(makeExactMulNSWRegion(Other.getSignedMax()));

Expand Down

0 comments on commit ab6667f

Please sign in to comment.