[llvm] [TTI][RISCV] Unconditionally break critical edges to sink ADDI (PR #108889)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 20:14:33 PDT 2024


================
@@ -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
----------------
preames wrote:

The test delta in this file needs a bit of explanation.  Most of the diff is me trying to understand the testing to find the actual problem.  The only actual change is this line.

Essentially, the original test is confused about what's it's testing.  "32" *can* be handled via the c.addi offset scheme.  However, here's the originally assembly we got:

```
	addi	a1, a0, -32
	li	a0, -99
	bnez	a1, .LBB0_2
# %bb.1:
	li	a0, 42
.LBB0_2:
	ret
```
Note that the c.addi form can only be matched when source and destination register are the same.

One this change sinks the unrelated LI out of the way, the register allocator can do that, and we end up with a compressed addi.  

>From the naming of the test and the comment, this doesn't appear to have been the intended result, and thus I adjusted the constant to 33.  If reviewers agree that this is the right test update, I'm going to land a rework of this test file separately.  



https://github.com/llvm/llvm-project/pull/108889


More information about the llvm-commits mailing list