Skip to content

Commit

Permalink
[GlobalISel] Look through extends etc in CombinerHelper::matchConstantOp
Browse files Browse the repository at this point in the history
It's possible to end up with a zext or something in the way of a G_CONSTANT,
even pre-legalization. This can happen with memsets.

e.g.

https://godbolt.org/z/Bjc8cw

To make sure we can catch these cases, use `getConstantVRegValWithLookThrough`
instead of `mi_match`.

Differential Revision: https://reviews.llvm.org/D81875
  • Loading branch information
Jessica Paquette committed Jun 15, 2020
1 parent c8d0aaa commit 5a4c3f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,8 +1617,9 @@ bool CombinerHelper::matchEqualDefs(const MachineOperand &MOP1,
bool CombinerHelper::matchConstantOp(const MachineOperand &MOP, int64_t C) {
if (!MOP.isReg())
return false;
int64_t Cst;
return mi_match(MOP.getReg(), MRI, m_ICst(Cst)) && Cst == C;
// MIPatternMatch doesn't let us look through G_ZEXT etc.
auto ValAndVReg = getConstantVRegValWithLookThrough(MOP.getReg(), MRI);
return ValAndVReg && ValAndVReg->Value == C;
}

bool CombinerHelper::replaceSingleDefInstWithOperand(MachineInstr &MI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,24 @@ body: |
%op:_(s32) = G_SUB %x(s32), %cst
$w0 = COPY %op(s32)
RET_ReallyLR implicit $w0
...
---
name: look_through_zext
tracksRegLiveness: true
body: |
bb.0:
liveins: $x0
; CHECK-LABEL: name: look_through_zext
; CHECK: liveins: $x0
; CHECK: %zero:_(s8) = G_CONSTANT i8 0
; CHECK: %zext_zero:_(s64) = G_ZEXT %zero(s8)
; CHECK: $x0 = COPY %zext_zero(s64)
; CHECK: RET_ReallyLR implicit $x0
%zero:_(s8) = G_CONSTANT i8 0
%zext_zero:_(s64) = G_ZEXT %zero(s8)
%c:_(s64) = G_CONSTANT i64 72340172838076673
%mul:_(s64) = G_MUL %c, %zext_zero
$x0 = COPY %mul(s64)
RET_ReallyLR implicit $x0
...

0 comments on commit 5a4c3f6

Please sign in to comment.