@@ -748,6 +748,7 @@ static Value *tryFactorization(BinaryOperator &I, const SimplifyQuery &SQ,
748748// -> (arithmetic_shift Binop1((not X), Y), Amt)
749749
750750Instruction *InstCombinerImpl::foldBinOpShiftWithShift (BinaryOperator &I) {
751+ const DataLayout &DL = I.getModule ()->getDataLayout ();
751752 auto IsValidBinOpc = [](unsigned Opc) {
752753 switch (Opc) {
753754 default :
@@ -796,9 +797,10 @@ Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
796797
797798 // Otherwise, need mask that meets the below requirement.
798799 // (logic_shift (inv_logic_shift Mask, ShAmt), ShAmt) == Mask
799- return ConstantExpr::get (
800- ShOpc, ConstantExpr::get (GetInvShift (ShOpc), CMask, CShift),
801- CShift) == CMask;
800+ Constant *MaskInvShift =
801+ ConstantFoldBinaryOpOperands (GetInvShift (ShOpc), CMask, CShift, DL);
802+ return ConstantFoldBinaryOpOperands (ShOpc, MaskInvShift, CShift, DL) ==
803+ CMask;
802804 };
803805
804806 auto MatchBinOp = [&](unsigned ShOpnum) -> Instruction * {
@@ -868,7 +870,8 @@ Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
868870 if (!CanDistributeBinops (I.getOpcode (), BinOpc, ShOpc, CMask, CShift))
869871 return nullptr ;
870872
871- Constant *NewCMask = ConstantExpr::get (GetInvShift (ShOpc), CMask, CShift);
873+ Constant *NewCMask =
874+ ConstantFoldBinaryOpOperands (GetInvShift (ShOpc), CMask, CShift, DL);
872875 Value *NewBinOp2 = Builder.CreateBinOp (
873876 static_cast <Instruction::BinaryOps>(BinOpc), X, NewCMask);
874877 Value *NewBinOp1 = Builder.CreateBinOp (I.getOpcode (), Y, NewBinOp2);
0 commit comments