[llvm] b4afade - [InstCombine] Avoid use of ConstantExpr::getZExtOrBitcast() (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 00:44:50 PDT 2023
Author: Nikita Popov
Date: 2023-09-29T09:44:43+02:00
New Revision: b4afade17564c61e9baf8024f8cf6921bdb3bde3
URL: https://github.com/llvm/llvm-project/commit/b4afade17564c61e9baf8024f8cf6921bdb3bde3
DIFF: https://github.com/llvm/llvm-project/commit/b4afade17564c61e9baf8024f8cf6921bdb3bde3.diff
LOG: [InstCombine] Avoid use of ConstantExpr::getZExtOrBitcast() (NFC)
Use the constant folding API instead. In the second case using
IR builder should also work, but the way the instructions are
created an inserted there is very unusual, so I've left it alone.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index b4b5c49a3adb696..05928b005dd47c5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4246,7 +4246,12 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ,
/*isNUW=*/false, SQ.getWithInstruction(&I)));
if (!NewShAmt)
return nullptr;
- NewShAmt = ConstantExpr::getZExtOrBitCast(NewShAmt, WidestTy);
+ if (NewShAmt->getType() != WidestTy) {
+ NewShAmt =
+ ConstantFoldCastOperand(Instruction::ZExt, NewShAmt, WidestTy, SQ.DL);
+ if (!NewShAmt)
+ return nullptr;
+ }
unsigned WidestBitWidth = WidestTy->getScalarSizeInBits();
// Is the new shift amount smaller than the bit width?
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index a25a7dd4160d24e..83defd5816f5948 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -136,9 +136,14 @@ Value *InstCombinerImpl::reassociateShiftAmtsOfTwoSameDirectionShifts(
assert(IdenticalShOpcodes && "Should not get here with
diff erent shifts.");
- // All good, we can do this fold.
- NewShAmt = ConstantExpr::getZExtOrBitCast(NewShAmt, X->getType());
+ if (NewShAmt->getType() != X->getType()) {
+ NewShAmt = ConstantFoldCastOperand(Instruction::ZExt, NewShAmt,
+ X->getType(), SQ.DL);
+ if (!NewShAmt)
+ return nullptr;
+ }
+ // All good, we can do this fold.
BinaryOperator *NewShift = BinaryOperator::Create(ShiftOpcode, X, NewShAmt);
// The flags can only be propagated if there wasn't a trunc.
More information about the llvm-commits
mailing list