-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[TTI][RISCV] Unconditionally break critical edges to sink ADDI #108889
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 4 commits
3f4f26e
4c878bb
aeec393
4a89449
5fa0835
0617aac
b06c457
bc21dfd
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 |
|---|---|---|
|
|
@@ -3,43 +3,39 @@ | |
| ; The optimization should appear only with +c, otherwise default isel should be | ||
| ; choosen. | ||
| ; | ||
| ; RUN: cat %s | sed 's/CMPCOND/eq/g' | sed 's/RESBRNORMAL/beq/g' | \ | ||
| ; RUN: sed 's/RESBROPT/c.beqz/g' > %t.compress_eq | ||
| ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=+c,+f,+d -filetype=obj \ | ||
| ; RUN: -disable-block-placement < %t.compress_eq \ | ||
| ; RUN: cat %s | sed 's/CMPCOND/eq/g' \ | ||
| ; RUN: | llc -mtriple=riscv32 -target-abi ilp32d -mattr=+c,+f,+d \ | ||
| ; RUN: -filetype=obj -disable-block-placement \ | ||
| ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=+c,+f,+d -M no-aliases - \ | ||
| ; RUN: | FileCheck -check-prefix=RV32IFDC %t.compress_eq | ||
| ; RUN: | FileCheck -check-prefix=RV32IFDC %s | ||
| ; | ||
| ; RUN: cat %s | sed -e 's/CMPCOND/eq/g' | sed -e 's/RESBRNORMAL/beq/g'\ | ||
| ; RUN: | sed -e 's/RESBROPT/c.beqz/g' > %t.nocompr_eq | ||
| ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=-c,+f,+d -filetype=obj \ | ||
| ; RUN: -disable-block-placement < %t.nocompr_eq \ | ||
| ; RUN: cat %s | sed -e 's/CMPCOND/eq/g' \ | ||
| ; RUN: | llc -mtriple=riscv32 -target-abi ilp32d -mattr=-c,+f,+d \ | ||
| ; RUN: -filetype=obj -disable-block-placement \ | ||
| ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=-c,+f,+d -M no-aliases - \ | ||
| ; RUN: | FileCheck -check-prefix=RV32IFD %t.nocompr_eq | ||
| ; RUN: | FileCheck -check-prefix=RV32IFD %s | ||
| ; | ||
| ; RUN: cat %s | sed 's/CMPCOND/ne/g' | sed 's/RESBRNORMAL/bne/g' | \ | ||
| ; RUN: sed 's/RESBROPT/c.bnez/g' > %t.compress_neq | ||
| ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=+c,+f,+d -filetype=obj \ | ||
| ; RUN: -disable-block-placement < %t.compress_neq \ | ||
| ; RUN: cat %s | sed 's/CMPCOND/ne/g' \ | ||
| ; RUN: | llc -mtriple=riscv32 -target-abi ilp32d -mattr=+c,+f,+d \ | ||
| ; RUN: -filetype=obj -disable-block-placement \ | ||
| ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=+c,+f,+d -M no-aliases - \ | ||
| ; RUN: | FileCheck -check-prefix=RV32IFDC %t.compress_neq | ||
| ; RUN: | FileCheck -check-prefix=RV32IFDC %s | ||
| ; | ||
| ; RUN: cat %s | sed -e 's/CMPCOND/ne/g' | sed -e 's/RESBRNORMAL/bne/g'\ | ||
| ; RUN: | sed -e 's/RESBROPT/c.bnez/g' > %t.nocompr_neq | ||
| ; RUN: llc -mtriple=riscv32 -target-abi ilp32d -mattr=-c,+f,+d -filetype=obj \ | ||
| ; RUN: -disable-block-placement < %t.nocompr_neq \ | ||
| ; RUN: cat %s | sed -e 's/CMPCOND/ne/g' \ | ||
| ; RUN: | llc -mtriple=riscv32 -target-abi ilp32d -mattr=-c,+f,+d \ | ||
| ; RUN: -filetype=obj -disable-block-placement \ | ||
| ; RUN: | llvm-objdump -d --triple=riscv32 --mattr=-c,+f,+d -M no-aliases - \ | ||
| ; RUN: | FileCheck -check-prefix=RV32IFD %t.nocompr_neq | ||
| ; RUN: | FileCheck -check-prefix=RV32IFD %s | ||
|
|
||
|
|
||
| ; constant is small and fit in 6 bit (compress imm) | ||
| ; RV32IFDC-LABEL: <f_small_pos>: | ||
| ; RV32IFDC: c.li [[REG:.*]], 0x14 | ||
| ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_small_pos>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, 0x14 | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_small_pos(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, 20 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -49,11 +45,11 @@ define i32 @f_small_pos(i32 %in0) minsize { | |
| ; constant is small and fit in 6 bit (compress imm) | ||
| ; RV32IFDC-LABEL: <f_small_neg>: | ||
| ; RV32IFDC: c.li [[REG:.*]], -0x14 | ||
| ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_small_neg>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, -0x14 | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_small_neg(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, -20 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -63,11 +59,11 @@ define i32 @f_small_neg(i32 %in0) minsize { | |
| ; constant is small and fit in 6 bit (compress imm) | ||
| ; RV32IFDC-LABEL: <f_small_edge_pos>: | ||
| ; RV32IFDC: c.li [[REG:.*]], 0x1f | ||
| ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_small_edge_pos>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, 0x1f | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_small_edge_pos(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, 31 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -77,11 +73,11 @@ define i32 @f_small_edge_pos(i32 %in0) minsize { | |
| ; constant is small and fit in 6 bit (compress imm) | ||
| ; RV32IFDC-LABEL: <f_small_edge_neg>: | ||
| ; RV32IFDC: c.li [[REG:.*]], -0x20 | ||
| ; RV32IFDC: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_small_edge_neg>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, -0x20 | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_small_edge_neg(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, -32 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -91,14 +87,14 @@ define i32 @f_small_edge_neg(i32 %in0) minsize { | |
| ; constant is medium and not fit in 6 bit (compress imm), | ||
| ; but fit in 12 bit (imm) | ||
| ; RV32IFDC-LABEL: <f_medium_ledge_pos>: | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x20 | ||
| ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x21 | ||
| ; RV32IFDC: [[COND:c.b.*]] [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_medium_ledge_pos>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, 0x20 | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: addi [[REG:.*]], zero, 0x21 | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_medium_ledge_pos(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, 32 | ||
| %cmp = icmp CMPCOND i32 %in0, 33 | ||
|
||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
| ret i32 %toRet | ||
| } | ||
|
|
@@ -107,11 +103,11 @@ define i32 @f_medium_ledge_pos(i32 %in0) minsize { | |
| ; but fit in 12 bit (imm) | ||
| ; RV32IFDC-LABEL: <f_medium_ledge_neg>: | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], 0x21 | ||
| ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:c.b.*]] [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_medium_ledge_neg>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, -0x21 | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_medium_ledge_neg(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, -33 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -122,11 +118,11 @@ define i32 @f_medium_ledge_neg(i32 %in0) minsize { | |
| ; but fit in 12 bit (imm) | ||
| ; RV32IFDC-LABEL: <f_medium_pos>: | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x3f | ||
| ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:c.b.*]] [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_medium_pos>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, 0x3f | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_medium_pos(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, 63 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -137,11 +133,11 @@ define i32 @f_medium_pos(i32 %in0) minsize { | |
| ; but fit in 12 bit (imm) | ||
| ; RV32IFDC-LABEL: <f_medium_neg>: | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], 0x3f | ||
| ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:c.b.*]] [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_medium_neg>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, -0x3f | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_medium_neg(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, -63 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -152,11 +148,11 @@ define i32 @f_medium_neg(i32 %in0) minsize { | |
| ; but fit in 12 bit (imm) | ||
| ; RV32IFDC-LABEL: <f_medium_bedge_pos>: | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], -0x7ff | ||
| ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:c.b.*]] [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_medium_bedge_pos>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, 0x7ff | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_medium_bedge_pos(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, 2047 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -167,11 +163,11 @@ define i32 @f_medium_bedge_pos(i32 %in0) minsize { | |
| ; but fit in 12 bit (imm), negative value fit in 12 bit too. | ||
| ; RV32IFDC-LABEL: <f_medium_bedge_neg>: | ||
| ; RV32IFDC: addi [[MAYZEROREG:.*]], [[REG:.*]], 0x7ff | ||
| ; RV32IFDC: RESBROPT [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; RV32IFDC: [[COND:c.b.*]] [[MAYZEROREG]], [[PLACE:.*]] | ||
| ; --- no compress extension | ||
| ; RV32IFD-LABEL: <f_medium_bedge_neg>: | ||
| ; RV32IFD: addi [[REG:.*]], zero, -0x7ff | ||
| ; RV32IFD: RESBRNORMAL [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| ; RV32IFD: [[COND:b.*]] [[ANOTHER:.*]], [[REG]], [[PLACE:.*]] | ||
| define i32 @f_medium_bedge_neg(i32 %in0) minsize { | ||
| %cmp = icmp CMPCOND i32 %in0, -2047 | ||
| %toRet = select i1 %cmp, i32 -99, i32 42 | ||
|
|
@@ -180,7 +176,7 @@ define i32 @f_medium_bedge_neg(i32 %in0) minsize { | |
|
|
||
| ; constant is big and do not fit in 12 bit (imm), fit in i32 | ||
| ; RV32IFDC-LABEL: <f_big_ledge_pos>: | ||
| ; RV32IFDC-NOT: RESBROPT | ||
| ; RV32IFDC-NOT: c.b | ||
| ; --- no compress extension | ||
| ; nothing to check. | ||
| define i32 @f_big_ledge_pos(i32 %in0) minsize { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,22 +61,22 @@ define signext i32 @select_const_int_pow2_zero(i1 zeroext %a) nounwind { | |
| define signext i32 @select_const_int_harder(i1 zeroext %a) nounwind { | ||
| ; RV32-LABEL: select_const_int_harder: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: mv a1, a0 | ||
| ; RV32-NEXT: li a0, 6 | ||
| ; RV32-NEXT: bnez a1, .LBB3_2 | ||
| ; RV32-NEXT: bnez a0, .LBB3_2 | ||
| ; RV32-NEXT: # %bb.1: | ||
| ; RV32-NEXT: li a0, 38 | ||
| ; RV32-NEXT: ret | ||
| ; RV32-NEXT: .LBB3_2: | ||
| ; RV32-NEXT: li a0, 6 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: select_const_int_harder: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: mv a1, a0 | ||
| ; RV64-NEXT: li a0, 6 | ||
| ; RV64-NEXT: bnez a1, .LBB3_2 | ||
| ; RV64-NEXT: bnez a0, .LBB3_2 | ||
| ; RV64-NEXT: # %bb.1: | ||
| ; RV64-NEXT: li a0, 38 | ||
| ; RV64-NEXT: ret | ||
| ; RV64-NEXT: .LBB3_2: | ||
| ; RV64-NEXT: li a0, 6 | ||
|
Collaborator
Author
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. These select lowering changes are arguably real regressions. We are loosing the opportunity to allocate the untaken result into a register and then conditionally overwrite it. The tail duplication probably wouldn't happen in real code, so we'd end up emitting an extra unconditional jump to bypass the critical edge we split before the join. Specifically for these selects in tests, most can be done via arithmetic expansions instead. I started to implement that, but ended up pulling on a few too many intertwined changes. I do plan to go back to this, but I don't consider the select impact blocking here. |
||
| ; RV64-NEXT: ret | ||
| %1 = select i1 %a, i32 6, i32 38 | ||
| ret i32 %1 | ||
|
|
||
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.
Is REG here
zerolike in the RV32IFD case?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.
Nevermind. It's not.