[llvm] 23a5073 - [RISCV] LUI used for address computation should not isAsCheapAsAMove
Ben Shi via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 23:21:48 PST 2022
Author: Haocong.Lu
Date: 2022-02-12T07:14:38Z
New Revision: 23a50736004e94704a2393aa36a905d737f2b20f
URL: https://github.com/llvm/llvm-project/commit/23a50736004e94704a2393aa36a905d737f2b20f
DIFF: https://github.com/llvm/llvm-project/commit/23a50736004e94704a2393aa36a905d737f2b20f.diff
LOG: [RISCV] LUI used for address computation should not isAsCheapAsAMove
A LUI instruction with flag RISCVII::MO_HI is usually used in conjunction
with ADDI, and jointly complete address computation. To bind the cost
evaluation of address computation, the LUI should not be regarded as a cheap
move separately, which is consistent with ADDI.
In this test case, it improves the unroll-loop code that the rematerialization
of array's base address miss MachineCSE with Heuristics #1 at isProfitableToCSE.
Reviewed By: asb, frasercrmck
Differential Revision: https://reviews.llvm.org/D118216
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/test/CodeGen/RISCV/unroll-loop-cse.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index f64717a6d88b8..4f39b9c8a9829 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -998,6 +998,8 @@ bool RISCVInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
return (MI.getOperand(1).isReg() &&
MI.getOperand(1).getReg() == RISCV::X0) ||
(MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0);
+ case RISCV::LUI:
+ return MI.getOperand(1).getTargetFlags() != RISCVII::MO_HI;
}
return MI.isAsCheapAsAMove();
}
diff --git a/llvm/test/CodeGen/RISCV/unroll-loop-cse.ll b/llvm/test/CodeGen/RISCV/unroll-loop-cse.ll
index 00b0d32e07d30..91aec53c47210 100644
--- a/llvm/test/CodeGen/RISCV/unroll-loop-cse.ll
+++ b/llvm/test/CodeGen/RISCV/unroll-loop-cse.ll
@@ -18,28 +18,20 @@ define signext i32 @unroll_loop_cse() {
; CHECK-NEXT: bne a3, a4, .LBB0_6
; CHECK-NEXT: # %bb.1:
; CHECK-NEXT: addi a1, a1, %lo(x)
-; CHECK-NEXT: lw a1, 4(a1)
+; CHECK-NEXT: lw a3, 4(a1)
; CHECK-NEXT: addi a2, a2, %lo(check)
-; CHECK-NEXT: lw a2, 4(a2)
-; CHECK-NEXT: bne a1, a2, .LBB0_6
+; CHECK-NEXT: lw a4, 4(a2)
+; CHECK-NEXT: bne a3, a4, .LBB0_6
; CHECK-NEXT: # %bb.2:
-; CHECK-NEXT: lui a1, %hi(x)
-; CHECK-NEXT: addi a1, a1, %lo(x)
; CHECK-NEXT: lw a3, 8(a1)
-; CHECK-NEXT: lui a2, %hi(check)
-; CHECK-NEXT: addi a2, a2, %lo(check)
; CHECK-NEXT: lw a4, 8(a2)
; CHECK-NEXT: bne a3, a4, .LBB0_6
; CHECK-NEXT: # %bb.3:
-; CHECK-NEXT: lw a1, 12(a1)
-; CHECK-NEXT: lw a2, 12(a2)
-; CHECK-NEXT: bne a1, a2, .LBB0_6
+; CHECK-NEXT: lw a3, 12(a1)
+; CHECK-NEXT: lw a4, 12(a2)
+; CHECK-NEXT: bne a3, a4, .LBB0_6
; CHECK-NEXT: # %bb.4:
-; CHECK-NEXT: lui a1, %hi(x)
-; CHECK-NEXT: addi a1, a1, %lo(x)
; CHECK-NEXT: lw a3, 16(a1)
-; CHECK-NEXT: lui a2, %hi(check)
-; CHECK-NEXT: addi a2, a2, %lo(check)
; CHECK-NEXT: lw a4, 16(a2)
; CHECK-NEXT: bne a3, a4, .LBB0_6
; CHECK-NEXT: # %bb.5:
More information about the llvm-commits
mailing list