Skip to content

Commit 087160b

Browse files
committed
Use TLI.isZExtFree and TLI.isTruncateFree
1 parent d63456e commit 087160b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -3154,10 +3154,22 @@ bool CombinerHelper::matchHoistLogicOpWithSameOpcodeHands(
31543154
return false;
31553155
case TargetOpcode::G_ANYEXT:
31563156
case TargetOpcode::G_SEXT:
3157-
case TargetOpcode::G_ZEXT:
3158-
case TargetOpcode::G_TRUNC: {
3157+
case TargetOpcode::G_ZEXT: {
31593158
// Match: logic (ext X), (ext Y) --> ext (logic X, Y)
3159+
break;
3160+
}
3161+
case TargetOpcode::G_TRUNC: {
31603162
// Match: logic (trunc X), (trunc Y) -> trunc (logic X, Y)
3163+
MachineFunction *MF = MI.getMF();
3164+
EVT DstEVT = getApproximateEVTForLLT(MRI.getType(Dst), MF->getDataLayout(),
3165+
MF->getFunction().getContext());
3166+
EVT XEVT = getApproximateEVTForLLT(XTy, MF->getDataLayout(),
3167+
MF->getFunction().getContext());
3168+
const TargetLowering &TLI = getTargetLowering();
3169+
// Be extra careful sinking truncate. If it's free, there's no benefit in
3170+
// widening a binop.
3171+
if (TLI.isZExtFree(DstEVT, XEVT) && TLI.isTruncateFree(XEVT, DstEVT))
3172+
return false;
31613173
break;
31623174
}
31633175
case TargetOpcode::G_AND:

llvm/test/CodeGen/AArch64/GlobalISel/prelegalizer-combiner-narrow-binop-feeding-add.mir

+8-6
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ body: |
8484
; CHECK: liveins: $x0, $x1
8585
; CHECK: %binop_lhs:_(s64) = COPY $x0
8686
; CHECK: %binop_rhs:_(s64) = COPY $x1
87-
; CHECK: [[AND:%[0-9]+]]:_(s64) = G_AND %binop_lhs, %binop_rhs
88-
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[AND]](s64)
89-
; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[TRUNC]](s32)
87+
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
88+
; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
89+
; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[TRUNC]], [[TRUNC1]]
90+
; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[AND]](s32)
9091
; CHECK: $x0 = COPY [[ZEXT]](s64)
9192
; CHECK: RET_ReallyLR implicit $x0
9293
%binop_lhs:_(s64) = COPY $x0
@@ -130,9 +131,10 @@ body: |
130131
; CHECK: liveins: $x0, $x1
131132
; CHECK: %binop_lhs:_(s64) = COPY $x0
132133
; CHECK: %binop_rhs:_(s64) = COPY $x1
133-
; CHECK: [[XOR:%[0-9]+]]:_(s64) = G_XOR %binop_lhs, %binop_rhs
134-
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[XOR]](s64)
135-
; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[TRUNC]](s32)
134+
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
135+
; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
136+
; CHECK: [[XOR:%[0-9]+]]:_(s32) = G_XOR [[TRUNC]], [[TRUNC1]]
137+
; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[XOR]](s32)
136138
; CHECK: $x0 = COPY [[ZEXT]](s64)
137139
; CHECK: RET_ReallyLR implicit $x0
138140
%binop_lhs:_(s64) = COPY $x0

0 commit comments

Comments
 (0)