Skip to content

Commit 376c026

Browse files
committed
Use TLI.isZExtFree and TLI.isTruncateFree
1 parent efc1440 commit 376c026

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
@@ -3153,10 +3153,22 @@ bool CombinerHelper::matchHoistLogicOpWithSameOpcodeHands(
31533153
return false;
31543154
case TargetOpcode::G_ANYEXT:
31553155
case TargetOpcode::G_SEXT:
3156-
case TargetOpcode::G_ZEXT:
3157-
case TargetOpcode::G_TRUNC: {
3156+
case TargetOpcode::G_ZEXT: {
31583157
// Match: logic (ext X), (ext Y) --> ext (logic X, Y)
3158+
break;
3159+
}
3160+
case TargetOpcode::G_TRUNC: {
31593161
// Match: logic (trunc X), (trunc Y) -> trunc (logic X, Y)
3162+
MachineFunction *MF = MI.getMF();
3163+
EVT DstEVT = getApproximateEVTForLLT(MRI.getType(Dst), MF->getDataLayout(),
3164+
MF->getFunction().getContext());
3165+
EVT XEVT = getApproximateEVTForLLT(XTy, MF->getDataLayout(),
3166+
MF->getFunction().getContext());
3167+
const TargetLowering &TLI = getTargetLowering();
3168+
// Be extra careful sinking truncate. If it's free, there's no benefit in
3169+
// widening a binop.
3170+
if (TLI.isZExtFree(DstEVT, XEVT) && TLI.isTruncateFree(XEVT, DstEVT))
3171+
return false;
31603172
break;
31613173
}
31623174
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)