[llvm] 18279a5 - [ARM] Fix IT block generation after Thumb2SizeReduce with -Oz
Nicholas Guy via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 05:20:43 PDT 2020
Author: Nicholas Guy
Date: 2020-08-03T13:20:32+01:00
New Revision: 18279a54b5d3382874924d6a3c7775b7e22598dc
URL: https://github.com/llvm/llvm-project/commit/18279a54b5d3382874924d6a3c7775b7e22598dc
DIFF: https://github.com/llvm/llvm-project/commit/18279a54b5d3382874924d6a3c7775b7e22598dc.diff
LOG: [ARM] Fix IT block generation after Thumb2SizeReduce with -Oz
Fixes a regression caused by D82439, in which IT blocks were no longer being
generated when -Oz is present. This was due to the CPSR register being marked as
dead, while this case was not accounted for.
Differential Revision: https://reviews.llvm.org/D83667
Added:
Modified:
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
llvm/test/CodeGen/Thumb2/constant-hoisting.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
index b501dc06ca72..0353cfd3d86f 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -587,6 +587,13 @@ bool ARMBaseInstrInfo::DefinesPredicate(
const MachineOperand &MO = MI.getOperand(i);
if ((MO.isRegMask() && MO.clobbersPhysReg(ARM::CPSR)) ||
(MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR)) {
+
+ // Filter out T1 instructions that have a dead CPSR,
+ // allowing IT blocks to be generated containing T1 instructions
+ const MCInstrDesc &MCID = MI.getDesc();
+ if (MCID.TSFlags & ARMII::ThumbArithFlagSetting && MO.isDead())
+ continue;
+
Pred.push_back(MO);
Found = true;
}
diff --git a/llvm/test/CodeGen/Thumb2/constant-hoisting.ll b/llvm/test/CodeGen/Thumb2/constant-hoisting.ll
index 5c8f934ce61d..a106900dc3e9 100644
--- a/llvm/test/CodeGen/Thumb2/constant-hoisting.ll
+++ b/llvm/test/CodeGen/Thumb2/constant-hoisting.ll
@@ -37,26 +37,25 @@ define i32 @test_values(i32 %a, i32 %b) minsize optsize {
; CHECK-V7M: mov r2, r0
; CHECK-V7M-NEXT: ldr r0, .LCPI0_0
; CHECK-V7M-NEXT: cmp r2, #50
-; CHECK-V7M-NEXT: beq .LBB0_5
+; CHECK-V7M-NEXT: beq .LBB0_3
; CHECK-V7M-NEXT: cmp r2, #1
-; CHECK-V7M-NEXT: beq .LBB0_7
+; CHECK-V7M-NEXT: ittt eq
+; CHECK-V7M-NEXT: addeq r0, r1
+; CHECK-V7M-NEXT: addeq r0, #1
+; CHECK-V7M-NEXT: bxeq lr
; CHECK-V7M-NEXT: cmp r2, #30
-; CHECK-V7M-NEXT: beq .LBB0_8
-; CHECK-V7M-NEXT: cbnz r2, .LBB0_6
+; CHECK-V7M-NEXT: ittt eq
+; CHECK-V7M-NEXT: addeq r0, r1
+; CHECK-V7M-NEXT: addeq r0, #2
+; CHECK-V7M-NEXT: bxeq lr
+; CHECK-V7M-NEXT: cbnz r2, .LBB0_4
+; CHECK-V7M-NEXT: .LBB0_2:
; CHECK-V7M-NEXT: add r0, r1
; CHECK-V7M-NEXT: bx lr
-; CHECK-V7M-NEXT: .LBB0_5:
+; CHECK-V7M-NEXT: .LBB0_3:
; CHECK-V7M-NEXT: add r0, r1
; CHECK-V7M-NEXT: adds r0, #4
-; CHECK-V7M-NEXT: .LBB0_6:
-; CHECK-V7M-NEXT: bx lr
-; CHECK-V7M-NEXT: .LBB0_7:
-; CHECK-V7M-NEXT: add r0, r1
-; CHECK-V7M-NEXT: adds r0, #1
-; CHECK-V7M-NEXT: bx lr
-; CHECK-V7M-NEXT: .LBB0_8:
-; CHECK-V7M-NEXT: add r0, r1
-; CHECK-V7M-NEXT: adds r0, #2
+; CHECK-V7M-NEXT: .LBB0_4:
; CHECK-V7M-NEXT: bx lr
; CHECK-V7M-NEXT: .p2align 2
; CHECK-V7M-NEXT: .LCPI0_0:
More information about the llvm-commits
mailing list