Skip to content

Commit 2ada7e7

Browse files
committed
[ARM] Resolve FIXME: Transform "(and (shl x, c2) c1)" into "(shl (and x, c1>>c2), c2)"
Transform "(and (shl x, c2) c1)" into "(shl (and x, c1>>c2), c2)" if "c1 >> c2" is a cheaper immediate than "c1" using HasLowerConstantMaterializationCost.
1 parent 715567d commit 2ada7e7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14388,9 +14388,16 @@ static SDValue CombineANDShift(SDNode *N,
1438814388
}
1438914389
}
1439014390

14391-
// FIXME: Transform "(and (shl x, c2) c1)" ->
14392-
// "(shl (and x, c1>>c2), c2)" if "c1 >> c2" is a cheaper immediate than
14393-
// c1.
14391+
// Transform "(and (shl x, c2) c1)" into "(shl (and x, c1>>c2), c2)"
14392+
// if "c1 >> c2" is a cheaper immediate than "c1"
14393+
if (HasLowerConstantMaterializationCost(C1 >> C2, C1, Subtarget)) {
14394+
14395+
SDValue And = DAG.getNode(ISD::AND, DL, MVT::i32, N0->getOperand(0),
14396+
DAG.getConstant(C1 >> C2, DL, MVT::i32));
14397+
return DAG.getNode(ISD::SHL, DL, MVT::i32, And,
14398+
DAG.getConstant(C2, DL, MVT::i32));
14399+
}
14400+
1439414401
return SDValue();
1439514402
}
1439614403

0 commit comments

Comments
 (0)