@@ -1846,27 +1846,29 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
1846
1846
if (CastOpcode != Cast1->getOpcode ())
1847
1847
return nullptr ;
1848
1848
1849
- // If the source types do not match, but the casts are matching extends, we
1850
- // can still narrow the logic op.
1851
- if (SrcTy != Cast1->getSrcTy ()) {
1852
- Value *X, *Y;
1853
- if (match (Cast0, m_OneUse (m_ZExtOrSExt (m_Value (X)))) &&
1854
- match (Cast1, m_OneUse (m_ZExtOrSExt (m_Value (Y))))) {
1855
- // Cast the narrower source to the wider source type.
1856
- unsigned XNumBits = X->getType ()->getScalarSizeInBits ();
1857
- unsigned YNumBits = Y->getType ()->getScalarSizeInBits ();
1858
- if (XNumBits < YNumBits)
1859
- X = Builder.CreateCast (CastOpcode, X, Y->getType ());
1860
- else
1861
- Y = Builder.CreateCast (CastOpcode, Y, X->getType ());
1862
- // Do the logic op in the intermediate width, then widen more.
1863
- Value *NarrowLogic = Builder.CreateBinOp (LogicOpc, X, Y);
1864
- return CastInst::Create (CastOpcode, NarrowLogic, DestTy);
1865
- }
1849
+ Value *X, *Y;
1850
+ if (match (Cast0, m_OneUse (m_ZExtOrSExt (m_Value (X)))) &&
1851
+ match (Cast1, m_OneUse (m_ZExtOrSExt (m_Value (Y))))) {
1852
+ // Cast the narrower source to the wider source type.
1853
+ unsigned XNumBits = X->getType ()->getScalarSizeInBits ();
1854
+ unsigned YNumBits = Y->getType ()->getScalarSizeInBits ();
1855
+ // If the source types do not match, but the casts are matching extends, we
1856
+ // can still narrow the logic op.
1857
+ if (XNumBits < YNumBits)
1858
+ X = Builder.CreateCast (CastOpcode, X, Y->getType ());
1859
+ else if (YNumBits < XNumBits)
1860
+ Y = Builder.CreateCast (CastOpcode, Y, X->getType ());
1861
+
1862
+ // Do the logic op in the intermediate width, then widen more.
1863
+ Value *NarrowLogic = Builder.CreateBinOp (LogicOpc, X, Y);
1864
+ if (auto *Disjoint = dyn_cast<PossiblyDisjointInst>(&I);
1865
+ Disjoint && Disjoint->isDisjoint ())
1866
+ cast<PossiblyDisjointInst>(NarrowLogic)->setIsDisjoint (true );
1867
+ return CastInst::Create (CastOpcode, NarrowLogic, DestTy);
1868
+ }
1866
1869
1867
- // Give up for other cast opcodes.
1870
+ if (SrcTy != Cast1-> getSrcTy ())
1868
1871
return nullptr ;
1869
- }
1870
1872
1871
1873
Value *Cast0Src = Cast0->getOperand (0 );
1872
1874
Value *Cast1Src = Cast1->getOperand (0 );
0 commit comments