@@ -748,6 +748,7 @@ static Value *tryFactorization(BinaryOperator &I, const SimplifyQuery &SQ,
748
748
// -> (arithmetic_shift Binop1((not X), Y), Amt)
749
749
750
750
Instruction *InstCombinerImpl::foldBinOpShiftWithShift (BinaryOperator &I) {
751
+ const DataLayout &DL = I.getModule ()->getDataLayout ();
751
752
auto IsValidBinOpc = [](unsigned Opc) {
752
753
switch (Opc) {
753
754
default :
@@ -796,9 +797,10 @@ Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
796
797
797
798
// Otherwise, need mask that meets the below requirement.
798
799
// (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;
802
804
};
803
805
804
806
auto MatchBinOp = [&](unsigned ShOpnum) -> Instruction * {
@@ -868,7 +870,8 @@ Instruction *InstCombinerImpl::foldBinOpShiftWithShift(BinaryOperator &I) {
868
870
if (!CanDistributeBinops (I.getOpcode (), BinOpc, ShOpc, CMask, CShift))
869
871
return nullptr ;
870
872
871
- Constant *NewCMask = ConstantExpr::get (GetInvShift (ShOpc), CMask, CShift);
873
+ Constant *NewCMask =
874
+ ConstantFoldBinaryOpOperands (GetInvShift (ShOpc), CMask, CShift, DL);
872
875
Value *NewBinOp2 = Builder.CreateBinOp (
873
876
static_cast <Instruction::BinaryOps>(BinOpc), X, NewCMask);
874
877
Value *NewBinOp1 = Builder.CreateBinOp (I.getOpcode (), Y, NewBinOp2);
0 commit comments