Skip to content

Commit 057bd35

Browse files
committed
add combiner rule for i32 trunc (i64 srl (i64 build_pair (X, Y)), 32) -> i32 Y
Rule: i32 = truncate (i64 = srl (i64 = build_pair (i32 X, i32 Y)), 32) -> i32 Y
1 parent 7b4a775 commit 057bd35

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
878878
// i64 = or (i64 = zero_extend X, i64 = shl (i64 = any_extend Y, 32))
879879
// -> i64 = build_pair (X, Y)
880880
setTargetDAGCombine(ISD::OR);
881+
// i32 = truncate (i64 = srl (i64 = build_pair (X, Y), 32))
882+
// -> i32 Y
883+
setTargetDAGCombine(ISD::TRUNCATE);
881884
}
882885

883886
// These map to conversion instructions for scalar FP types.
@@ -5297,6 +5300,28 @@ static SDValue PerformORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
52975300
return SDValue();
52985301
}
52995302

5303+
static SDValue PerformTRUNCATECombine(SDNode *N,
5304+
TargetLowering::DAGCombinerInfo &DCI,
5305+
CodeGenOptLevel OptLevel) {
5306+
if (OptLevel == CodeGenOptLevel::None)
5307+
return SDValue();
5308+
5309+
SDValue Op = N->getOperand(0);
5310+
if (Op.getOpcode() == ISD::SRL) {
5311+
SDValue SrlOp = Op.getOperand(0);
5312+
SDValue SrlSh = Op.getOperand(1);
5313+
// i32 = truncate (i64 = srl (i64 build_pair (A, B), 32))
5314+
// -> i32 A
5315+
if (const auto *Const = dyn_cast<ConstantSDNode>(SrlSh);
5316+
Const && Const->getZExtValue() == 32) {
5317+
if (SrlOp.getOpcode() == ISD::BUILD_PAIR)
5318+
return SrlOp.getOperand(1);
5319+
}
5320+
}
5321+
5322+
return SDValue();
5323+
}
5324+
53005325
SDValue NVPTXTargetLowering::PerformDAGCombine(SDNode *N,
53015326
DAGCombinerInfo &DCI) const {
53025327
CodeGenOptLevel OptLevel = getTargetMachine().getOptLevel();
@@ -5333,6 +5358,8 @@ SDValue NVPTXTargetLowering::PerformDAGCombine(SDNode *N,
53335358
return PerformBUILD_VECTORCombine(N, DCI);
53345359
case ISD::OR:
53355360
return PerformORCombine(N, DCI, OptLevel);
5361+
case ISD::TRUNCATE:
5362+
return PerformTRUNCATECombine(N, DCI, OptLevel);
53365363
}
53375364
return SDValue();
53385365
}

0 commit comments

Comments
 (0)