Skip to content

Commit 43177b5

Browse files
authored
[GISel] Add more FP opcodes to CSE (#123624)
This fixes #122724
1 parent ff0f1dd commit 43177b5

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111
#include "llvm/CodeGen/GlobalISel/CSEInfo.h"
1212
#include "llvm/CodeGen/MachineRegisterInfo.h"
13+
#include "llvm/CodeGen/TargetOpcodes.h"
1314
#include "llvm/InitializePasses.h"
1415
#include "llvm/Support/Error.h"
1516

@@ -65,6 +66,16 @@ bool CSEConfigFull::shouldCSEOpc(unsigned Opc) {
6566
case TargetOpcode::G_BUILD_VECTOR:
6667
case TargetOpcode::G_BUILD_VECTOR_TRUNC:
6768
case TargetOpcode::G_SEXT_INREG:
69+
case TargetOpcode::G_FADD:
70+
case TargetOpcode::G_FSUB:
71+
case TargetOpcode::G_FMUL:
72+
case TargetOpcode::G_FDIV:
73+
case TargetOpcode::G_FABS:
74+
// TODO: support G_FNEG.
75+
case TargetOpcode::G_FMAXNUM:
76+
case TargetOpcode::G_FMINNUM:
77+
case TargetOpcode::G_FMAXNUM_IEEE:
78+
case TargetOpcode::G_FMINNUM_IEEE:
6879
return true;
6980
}
7081
return false;

llvm/unittests/CodeGen/GlobalISel/CSETest.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,121 @@ TEST_F(AArch64GISelMITest, TestCSE) {
7575
auto MIBUnmerge2 = CSEB.buildUnmerge({s32, s32}, Copies[0]);
7676
EXPECT_TRUE(&*MIBUnmerge == &*MIBUnmerge2);
7777

78+
// Check G_FADD
79+
{
80+
auto MIBFAdd = CSEB.buildFAdd(s32, Copies[0], Copies[1]);
81+
auto MIBFAdd2 = CSEB.buildFAdd(s32, Copies[0], Copies[1]);
82+
EXPECT_TRUE(&*MIBFAdd == &*MIBFAdd2);
83+
84+
MIBFAdd2.setFlag(MachineInstr::FmNsz);
85+
EXPECT_FALSE(&*MIBFAdd == &*MIBFAdd2);
86+
87+
MIBFAdd2.clearFlag(MachineInstr::FmNsz);
88+
EXPECT_TRUE(&*MIBFAdd == &*MIBFAdd2);
89+
}
90+
91+
// Check G_FSUB
92+
{
93+
auto MIBFSub = CSEB.buildFSub(s32, Copies[0], Copies[1]);
94+
auto MIBFSub2 = CSEB.buildFSub(s32, Copies[0], Copies[1]);
95+
EXPECT_TRUE(&*MIBFSub == &*MIBFSub2);
96+
97+
MIBFSub2.setFlag(MachineInstr::FmNoNans);
98+
EXPECT_FALSE(&*MIBFSub == &*MIBFSub2);
99+
100+
MIBFSub2.clearFlag(MachineInstr::FmNoNans);
101+
EXPECT_TRUE(&*MIBFSub == &*MIBFSub2);
102+
}
103+
104+
// Check G_FMUL
105+
{
106+
auto MIBFMul = CSEB.buildFMul(s32, Copies[0], Copies[1]);
107+
auto MIBFMul2 = CSEB.buildFMul(s32, Copies[0], Copies[1]);
108+
EXPECT_TRUE(&*MIBFMul == &*MIBFMul2);
109+
110+
MIBFMul2.setFlag(MachineInstr::FmNoNans);
111+
EXPECT_FALSE(&*MIBFMul == &*MIBFMul2);
112+
113+
MIBFMul2.clearFlag(MachineInstr::FmNoNans);
114+
EXPECT_TRUE(&*MIBFMul == &*MIBFMul2);
115+
}
116+
117+
// Check G_FDIV
118+
{
119+
auto MIBFDiv = CSEB.buildFDiv(s32, Copies[0], Copies[1]);
120+
auto MIBFDiv2 = CSEB.buildFDiv(s32, Copies[0], Copies[1]);
121+
EXPECT_TRUE(&*MIBFDiv == &*MIBFDiv2);
122+
123+
MIBFDiv2.setFlag(MachineInstr::FmNoNans);
124+
EXPECT_FALSE(&*MIBFDiv == &*MIBFDiv2);
125+
126+
MIBFDiv2.clearFlag(MachineInstr::FmNoNans);
127+
EXPECT_TRUE(&*MIBFDiv == &*MIBFDiv2);
128+
}
129+
130+
// Check G_FABS
131+
{
132+
auto MIBFAbs = CSEB.buildFAbs(s32, Copies[0]);
133+
auto MIBFAbs2 = CSEB.buildFAbs(s32, Copies[0]);
134+
EXPECT_TRUE(&*MIBFAbs == &*MIBFAbs2);
135+
136+
MIBFAbs2.setFlag(MachineInstr::FmNsz);
137+
EXPECT_FALSE(&*MIBFAbs == &*MIBFAbs2);
138+
139+
MIBFAbs2.clearFlag(MachineInstr::FmNsz);
140+
EXPECT_TRUE(&*MIBFAbs == &*MIBFAbs2);
141+
}
142+
143+
// Check G_FMINNUM/F_MAXNUM:
144+
{
145+
auto MIBFMinNum = CSEB.buildFMinNum(s32, Copies[0], Copies[1]);
146+
auto MIBFMinNum2 = CSEB.buildFMinNum(s32, Copies[0], Copies[1]);
147+
EXPECT_TRUE(&*MIBFMinNum == &*MIBFMinNum2);
148+
149+
MIBFMinNum2.setFlag(MachineInstr::FmNsz);
150+
EXPECT_FALSE(&*MIBFMinNum == &*MIBFMinNum2);
151+
152+
MIBFMinNum2.clearFlag(MachineInstr::FmNsz);
153+
EXPECT_TRUE(&*MIBFMinNum == &*MIBFMinNum2);
154+
}
155+
156+
{
157+
auto MIBFMaxNum = CSEB.buildFMaxNum(s32, Copies[0], Copies[1]);
158+
auto MIBFMaxNum2 = CSEB.buildFMaxNum(s32, Copies[0], Copies[1]);
159+
EXPECT_TRUE(&*MIBFMaxNum == &*MIBFMaxNum2);
160+
161+
MIBFMaxNum2.setFlag(MachineInstr::FmNsz);
162+
EXPECT_FALSE(&*MIBFMaxNum == &*MIBFMaxNum2);
163+
164+
MIBFMaxNum2.clearFlag(MachineInstr::FmNsz);
165+
EXPECT_TRUE(&*MIBFMaxNum == &*MIBFMaxNum2);
166+
}
167+
168+
// Check G_FMINNUM_IEEE/F_MAXNUM_IEEE:
169+
{
170+
auto MIBFMinNumIEEE = CSEB.buildFMinNumIEEE(s32, Copies[0], Copies[1]);
171+
auto MIBFMinNumIEEE2 = CSEB.buildFMinNumIEEE(s32, Copies[0], Copies[1]);
172+
EXPECT_TRUE(&*MIBFMinNumIEEE == &*MIBFMinNumIEEE2);
173+
174+
MIBFMinNumIEEE2.setFlag(MachineInstr::FmNsz);
175+
EXPECT_FALSE(&*MIBFMinNumIEEE == &*MIBFMinNumIEEE2);
176+
177+
MIBFMinNumIEEE2.clearFlag(MachineInstr::FmNsz);
178+
EXPECT_TRUE(&*MIBFMinNumIEEE == &*MIBFMinNumIEEE2);
179+
}
180+
181+
{
182+
auto MIBFMaxNumIEEE = CSEB.buildFMaxNumIEEE(s32, Copies[0], Copies[1]);
183+
auto MIBFMaxNumIEEE2 = CSEB.buildFMaxNumIEEE(s32, Copies[0], Copies[1]);
184+
EXPECT_TRUE(&*MIBFMaxNumIEEE == &*MIBFMaxNumIEEE2);
185+
186+
MIBFMaxNumIEEE2.setFlag(MachineInstr::FmNsz);
187+
EXPECT_FALSE(&*MIBFMaxNumIEEE == &*MIBFMaxNumIEEE2);
188+
189+
MIBFMaxNumIEEE2.clearFlag(MachineInstr::FmNsz);
190+
EXPECT_TRUE(&*MIBFMaxNumIEEE == &*MIBFMaxNumIEEE2);
191+
}
192+
78193
// Check G_BUILD_VECTOR
79194
Register Reg1 = MRI->createGenericVirtualRegister(s32);
80195
Register Reg2 = MRI->createGenericVirtualRegister(s32);

0 commit comments

Comments
 (0)