[llvm] b43b2a6 - [InstCombine] Avoid use of shift constant expressions (NFCI)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 07:58:18 PST 2023
Author: Nikita Popov
Date: 2023-11-10T16:58:10+01:00
New Revision: b43b2a64b5d12b8ecbe1bef0aff5c89c9860319e
URL: https://github.com/llvm/llvm-project/commit/b43b2a64b5d12b8ecbe1bef0aff5c89c9860319e
DIFF: https://github.com/llvm/llvm-project/commit/b43b2a64b5d12b8ecbe1bef0aff5c89c9860319e.diff
LOG: [InstCombine] Avoid use of shift constant expressions (NFCI)
Use the constant folding API instead. As we're working on
ImmConstants, these folds are guaranteed to succeed.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 2e0b185769041cc..16de4e3ffe1f51a 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -748,6 +748,7 @@ static Value *tryFactorization(BinaryOperator &I, const SimplifyQuery &SQ,
// -> (arithmetic_shift Binop1((not X), Y), Amt)
Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
+ const DataLayout &DL = I.getModule()->getDataLayout();
auto IsValidBinOpc = [](unsigned Opc) {
switch (Opc) {
default:
@@ -796,9 +797,10 @@ Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
// Otherwise, need mask that meets the below requirement.
// (logic_shift (inv_logic_shift Mask, ShAmt), ShAmt) == Mask
- return ConstantExpr::get(
- ShOpc, ConstantExpr::get(GetInvShift(ShOpc), CMask, CShift),
- CShift) == CMask;
+ Constant *MaskInvShift =
+ ConstantFoldBinaryOpOperands(GetInvShift(ShOpc), CMask, CShift, DL);
+ return ConstantFoldBinaryOpOperands(ShOpc, MaskInvShift, CShift, DL) ==
+ CMask;
};
auto MatchBinOp = [&](unsigned ShOpnum) -> Instruction * {
@@ -868,7 +870,8 @@ Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
if (!CanDistributeBinops(I.getOpcode(), BinOpc, ShOpc, CMask, CShift))
return nullptr;
- Constant *NewCMask = ConstantExpr::get(GetInvShift(ShOpc), CMask, CShift);
+ Constant *NewCMask =
+ ConstantFoldBinaryOpOperands(GetInvShift(ShOpc), CMask, CShift, DL);
Value *NewBinOp2 = Builder.CreateBinOp(
static_cast<Instruction::BinaryOps>(BinOpc), X, NewCMask);
Value *NewBinOp1 = Builder.CreateBinOp(I.getOpcode(), Y, NewBinOp2);
More information about the llvm-commits
mailing list