@@ -3295,32 +3295,22 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
3295
3295
}
3296
3296
3297
3297
// FIXME: This should not be limited to scalar (pull into APInt match above).
3298
- if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1)) {
3299
- if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) {
3300
- if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand (1 ))) {
3301
- if (Op0I->getOpcode () == Instruction::LShr) {
3302
- // ((X^C1) >> C2) ^ C3 -> (X>>C2) ^ ((C1>>C2)^C3)
3303
- // E1 = "X ^ C1"
3304
- BinaryOperator *E1 ;
3305
- ConstantInt *C1;
3306
- if (Op0I->hasOneUse () &&
3307
- (E1 = dyn_cast<BinaryOperator>(Op0I->getOperand (0 ))) &&
3308
- E1 ->getOpcode () == Instruction::Xor &&
3309
- (C1 = dyn_cast<ConstantInt>(E1 ->getOperand (1 )))) {
3310
- // fold (C1 >> C2) ^ C3
3311
- ConstantInt *C2 = Op0CI, *C3 = RHSC;
3312
- APInt FoldConst = C1->getValue ().lshr (C2->getValue ());
3313
- FoldConst ^= C3->getValue ();
3314
- // Prepare the two operands.
3315
- Value *Opnd0 = Builder.CreateLShr (E1 ->getOperand (0 ), C2);
3316
- Opnd0->takeName (Op0I);
3317
- cast<Instruction>(Opnd0)->setDebugLoc (I.getDebugLoc ());
3318
- Value *FoldVal = ConstantInt::get (Ty, FoldConst);
3319
-
3320
- return BinaryOperator::CreateXor (Opnd0, FoldVal);
3321
- }
3322
- }
3323
- }
3298
+ {
3299
+ Value *X;
3300
+ ConstantInt *C1, *C2, *C3;
3301
+ // ((X^C1) >> C2) ^ C3 -> (X>>C2) ^ ((C1>>C2)^C3)
3302
+ if (match (Op1, m_ConstantInt (C3)) &&
3303
+ match (Op0, m_LShr (m_Xor (m_Value (X), m_ConstantInt (C1)),
3304
+ m_ConstantInt (C2))) &&
3305
+ Op0->hasOneUse ()) {
3306
+ // fold (C1 >> C2) ^ C3
3307
+ APInt FoldConst = C1->getValue ().lshr (C2->getValue ());
3308
+ FoldConst ^= C3->getValue ();
3309
+ // Prepare the two operands.
3310
+ auto *Opnd0 = cast<Instruction>(Builder.CreateLShr (X, C2));
3311
+ Opnd0->takeName (cast<Instruction>(Op0));
3312
+ Opnd0->setDebugLoc (I.getDebugLoc ());
3313
+ return BinaryOperator::CreateXor (Opnd0, ConstantInt::get (Ty, FoldConst));
3324
3314
}
3325
3315
}
3326
3316
0 commit comments