-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[GISel][AArch64][AMDGPU][RISCV] Canonicalize (sub X, C) -> (add X, -C) #114309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
13c2599
fa7ec2b
78d79f0
1e3a249
27433ab
49fec4a
7efa9a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2041,6 +2041,28 @@ void CombinerHelper::applyCombineMulToShl(MachineInstr &MI, | |
| Observer.changedInstr(MI); | ||
| } | ||
|
|
||
| bool CombinerHelper::matchCombineSubToAdd(MachineInstr &MI, | ||
| BuildFnTy &MatchInfo) { | ||
| assert(MI.getOpcode() == TargetOpcode::G_SUB && "Expected a G_SUB"); | ||
|
||
| auto MaybeImmVal = | ||
| getIConstantVRegValWithLookThrough(MI.getOperand(2).getReg(), MRI); | ||
topperc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!MaybeImmVal) | ||
| return false; | ||
topperc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| LLT Ty = MRI.getType(MI.getOperand(0).getReg()); | ||
|
|
||
topperc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| APInt NegImm = -MaybeImmVal->Value; | ||
topperc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MatchInfo = [=, &MI](MachineIRBuilder &B) { | ||
| auto NegCst = B.buildConstant(Ty, NegImm); | ||
| Observer.changingInstr(MI); | ||
| MI.setDesc(B.getTII().get(TargetOpcode::G_ADD)); | ||
| MI.getOperand(2).setReg(NegCst.getReg(0)); | ||
| MI.clearFlag(MachineInstr::MIFlag::NoUWrap); | ||
| Observer.changedInstr(MI); | ||
| }; | ||
| return true; | ||
| } | ||
|
|
||
| // shl ([sza]ext x), y => zext (shl x, y), if shift does not overflow source | ||
| bool CombinerHelper::matchCombineShlOfExtend(MachineInstr &MI, | ||
| RegisterImmPair &MatchData) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1669,7 +1669,7 @@ define i65 @v_ashr_i65(i65 %value, i65 %amount) { | |
| ; GFX6-NEXT: v_sub_i32_e32 v8, vcc, 64, v3 | ||
| ; GFX6-NEXT: v_lshr_b64 v[6:7], v[0:1], v3 | ||
| ; GFX6-NEXT: v_lshl_b64 v[8:9], v[4:5], v8 | ||
| ; GFX6-NEXT: v_subrev_i32_e32 v2, vcc, 64, v3 | ||
| ; GFX6-NEXT: v_add_i32_e32 v2, vcc, 0xffffffc0, v3 | ||
| ; GFX6-NEXT: v_ashr_i64 v[10:11], v[4:5], v3 | ||
| ; GFX6-NEXT: v_or_b32_e32 v6, v6, v8 | ||
| ; GFX6-NEXT: v_ashrrev_i32_e32 v8, 31, v5 | ||
|
|
@@ -1692,7 +1692,7 @@ define i65 @v_ashr_i65(i65 %value, i65 %amount) { | |
| ; GFX8-NEXT: v_sub_u32_e32 v8, vcc, 64, v3 | ||
| ; GFX8-NEXT: v_lshrrev_b64 v[6:7], v3, v[0:1] | ||
| ; GFX8-NEXT: v_lshlrev_b64 v[8:9], v8, v[4:5] | ||
| ; GFX8-NEXT: v_subrev_u32_e32 v2, vcc, 64, v3 | ||
| ; GFX8-NEXT: v_add_u32_e32 v2, vcc, 0xffffffc0, v3 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is worse. We already have the patterns to undo this, but I guess they didn't import. |
||
| ; GFX8-NEXT: v_ashrrev_i64 v[10:11], v3, v[4:5] | ||
| ; GFX8-NEXT: v_or_b32_e32 v6, v6, v8 | ||
| ; GFX8-NEXT: v_ashrrev_i32_e32 v8, 31, v5 | ||
|
|
@@ -1715,7 +1715,7 @@ define i65 @v_ashr_i65(i65 %value, i65 %amount) { | |
| ; GFX9-NEXT: v_sub_u32_e32 v8, 64, v3 | ||
| ; GFX9-NEXT: v_lshrrev_b64 v[6:7], v3, v[0:1] | ||
| ; GFX9-NEXT: v_lshlrev_b64 v[8:9], v8, v[4:5] | ||
| ; GFX9-NEXT: v_subrev_u32_e32 v2, 64, v3 | ||
| ; GFX9-NEXT: v_add_u32_e32 v2, 0xffffffc0, v3 | ||
| ; GFX9-NEXT: v_ashrrev_i64 v[10:11], v3, v[4:5] | ||
| ; GFX9-NEXT: v_or_b32_e32 v6, v6, v8 | ||
| ; GFX9-NEXT: v_ashrrev_i32_e32 v8, 31, v5 | ||
|
|
@@ -1735,7 +1735,7 @@ define i65 @v_ashr_i65(i65 %value, i65 %amount) { | |
| ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) | ||
| ; GFX10-NEXT: v_bfe_i32 v4, v2, 0, 1 | ||
| ; GFX10-NEXT: v_sub_nc_u32_e32 v2, 64, v3 | ||
| ; GFX10-NEXT: v_subrev_nc_u32_e32 v10, 64, v3 | ||
| ; GFX10-NEXT: v_add_nc_u32_e32 v10, 0xffffffc0, v3 | ||
| ; GFX10-NEXT: v_lshrrev_b64 v[6:7], v3, v[0:1] | ||
| ; GFX10-NEXT: v_cmp_gt_u32_e32 vcc_lo, 64, v3 | ||
| ; GFX10-NEXT: v_ashrrev_i32_e32 v5, 31, v4 | ||
|
|
@@ -1758,7 +1758,7 @@ define i65 @v_ashr_i65(i65 %value, i65 %amount) { | |
| ; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) | ||
| ; GFX11-NEXT: v_bfe_i32 v4, v2, 0, 1 | ||
| ; GFX11-NEXT: v_sub_nc_u32_e32 v2, 64, v3 | ||
| ; GFX11-NEXT: v_subrev_nc_u32_e32 v10, 64, v3 | ||
| ; GFX11-NEXT: v_add_nc_u32_e32 v10, 0xffffffc0, v3 | ||
| ; GFX11-NEXT: v_lshrrev_b64 v[6:7], v3, v[0:1] | ||
| ; GFX11-NEXT: v_cmp_gt_u32_e32 vcc_lo, 64, v3 | ||
| ; GFX11-NEXT: v_ashrrev_i32_e32 v5, 31, v4 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you take a look at:
The example is unrelated, but it shows how to put a constant on a register. We want to match for G_SUB x, c.