Skip to content

Commit 220004d

Browse files
authored
[GISel] Add more FP opcodes to CSE (#123949)
Resubmit, previously PR has compilation issues.
1 parent ba17485 commit 220004d

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ bool CSEConfigFull::shouldCSEOpc(unsigned Opc) {
6565
case TargetOpcode::G_BUILD_VECTOR:
6666
case TargetOpcode::G_BUILD_VECTOR_TRUNC:
6767
case TargetOpcode::G_SEXT_INREG:
68+
case TargetOpcode::G_FADD:
69+
case TargetOpcode::G_FSUB:
70+
case TargetOpcode::G_FMUL:
71+
case TargetOpcode::G_FDIV:
72+
case TargetOpcode::G_FABS:
73+
// TODO: support G_FNEG.
74+
case TargetOpcode::G_FMAXNUM:
75+
case TargetOpcode::G_FMINNUM:
76+
case TargetOpcode::G_FMAXNUM_IEEE:
77+
case TargetOpcode::G_FMINNUM_IEEE:
6878
return true;
6979
}
7080
return false;

llvm/unittests/CodeGen/GlobalISel/CSETest.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,138 @@ 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+
auto MIBFAdd3 =
85+
CSEB.buildFAdd(s32, Copies[0], Copies[1], MachineInstr::FmNsz);
86+
EXPECT_FALSE(&*MIBFAdd == &*MIBFAdd3);
87+
88+
MIBFAdd2->setFlag(MachineInstr::FmNsz);
89+
MIBFAdd2->clearFlag(MachineInstr::FmNsz);
90+
EXPECT_TRUE(&*MIBFAdd == &*MIBFAdd2);
91+
}
92+
93+
// Check G_FSUB
94+
{
95+
auto MIBFSub = CSEB.buildFSub(s32, Copies[0], Copies[1]);
96+
auto MIBFSub2 = CSEB.buildFSub(s32, Copies[0], Copies[1]);
97+
EXPECT_TRUE(&*MIBFSub == &*MIBFSub2);
98+
99+
auto MIBFSub3 =
100+
CSEB.buildFSub(s32, Copies[0], Copies[1], MachineInstr::FmNoNans);
101+
EXPECT_FALSE(&*MIBFSub == &*MIBFSub3);
102+
103+
MIBFSub2->setFlag(MachineInstr::FmNoNans);
104+
MIBFSub2->clearFlag(MachineInstr::FmNoNans);
105+
EXPECT_TRUE(&*MIBFSub == &*MIBFSub2);
106+
}
107+
108+
// Check G_FMUL
109+
{
110+
auto MIBFMul = CSEB.buildFMul(s32, Copies[0], Copies[1]);
111+
auto MIBFMul2 = CSEB.buildFMul(s32, Copies[0], Copies[1]);
112+
EXPECT_TRUE(&*MIBFMul == &*MIBFMul2);
113+
114+
auto MIBFMul3 =
115+
CSEB.buildFMul(s32, Copies[0], Copies[1], MachineInstr::FmNoNans);
116+
EXPECT_FALSE(&*MIBFMul == &*MIBFMul3);
117+
118+
MIBFMul2->setFlag(MachineInstr::FmNoNans);
119+
MIBFMul2->clearFlag(MachineInstr::FmNoNans);
120+
EXPECT_TRUE(&*MIBFMul == &*MIBFMul2);
121+
}
122+
123+
// Check G_FDIV
124+
{
125+
auto MIBFDiv = CSEB.buildFDiv(s32, Copies[0], Copies[1]);
126+
auto MIBFDiv2 = CSEB.buildFDiv(s32, Copies[0], Copies[1]);
127+
EXPECT_TRUE(&*MIBFDiv == &*MIBFDiv2);
128+
129+
auto MIBFDiv3 =
130+
CSEB.buildFDiv(s32, Copies[0], Copies[1], MachineInstr::FmNoNans);
131+
EXPECT_FALSE(&*MIBFDiv == &*MIBFDiv3);
132+
133+
MIBFDiv2->setFlag(MachineInstr::FmNoNans);
134+
MIBFDiv2->clearFlag(MachineInstr::FmNoNans);
135+
EXPECT_TRUE(&*MIBFDiv == &*MIBFDiv2);
136+
}
137+
138+
// Check G_FABS
139+
{
140+
auto MIBFAbs = CSEB.buildFAbs(s32, Copies[0]);
141+
auto MIBFAbs2 = CSEB.buildFAbs(s32, Copies[0]);
142+
EXPECT_TRUE(&*MIBFAbs == &*MIBFAbs2);
143+
144+
auto MIBFAbs3 = CSEB.buildFAbs(s32, Copies[0], MachineInstr::FmNsz);
145+
EXPECT_FALSE(&*MIBFAbs == &*MIBFAbs3);
146+
147+
MIBFAbs2->setFlag(MachineInstr::FmNsz);
148+
MIBFAbs2->clearFlag(MachineInstr::FmNsz);
149+
EXPECT_TRUE(&*MIBFAbs == &*MIBFAbs2);
150+
}
151+
152+
// Check G_FMINNUM/F_MAXNUM:
153+
{
154+
auto MIBFMinNum = CSEB.buildFMinNum(s32, Copies[0], Copies[1]);
155+
auto MIBFMinNum2 = CSEB.buildFMinNum(s32, Copies[0], Copies[1]);
156+
EXPECT_TRUE(&*MIBFMinNum == &*MIBFMinNum2);
157+
158+
auto MIBFMinNum3 =
159+
CSEB.buildFMinNum(s32, Copies[0], Copies[1], MachineInstr::FmNsz);
160+
EXPECT_FALSE(&*MIBFMinNum == &*MIBFMinNum3);
161+
162+
MIBFMinNum2->setFlag(MachineInstr::FmNsz);
163+
MIBFMinNum2->clearFlag(MachineInstr::FmNsz);
164+
EXPECT_TRUE(&*MIBFMinNum == &*MIBFMinNum2);
165+
}
166+
167+
{
168+
auto MIBFMaxNum = CSEB.buildFMaxNum(s32, Copies[0], Copies[1]);
169+
auto MIBFMaxNum2 = CSEB.buildFMaxNum(s32, Copies[0], Copies[1]);
170+
EXPECT_TRUE(&*MIBFMaxNum == &*MIBFMaxNum2);
171+
172+
auto MIBFMaxNum3 =
173+
CSEB.buildFMaxNum(s32, Copies[0], Copies[1], MachineInstr::FmNsz);
174+
EXPECT_FALSE(&*MIBFMaxNum == &*MIBFMaxNum3);
175+
176+
MIBFMaxNum2->setFlag(MachineInstr::FmNsz);
177+
MIBFMaxNum2->clearFlag(MachineInstr::FmNsz);
178+
EXPECT_TRUE(&*MIBFMaxNum == &*MIBFMaxNum2);
179+
}
180+
181+
// Check G_FMINNUM_IEEE/F_MAXNUM_IEEE:
182+
{
183+
auto MIBFMinNumIEEE = CSEB.buildFMinNumIEEE(s32, Copies[0], Copies[1]);
184+
auto MIBFMinNumIEEE2 = CSEB.buildFMinNumIEEE(s32, Copies[0], Copies[1]);
185+
EXPECT_TRUE(&*MIBFMinNumIEEE == &*MIBFMinNumIEEE2);
186+
187+
auto MIBFMinNumIEEE3 =
188+
CSEB.buildFMinNumIEEE(s32, Copies[0], Copies[1], MachineInstr::FmNsz);
189+
EXPECT_FALSE(&*MIBFMinNumIEEE == &*MIBFMinNumIEEE3);
190+
191+
MIBFMinNumIEEE2->setFlag(MachineInstr::FmNsz);
192+
MIBFMinNumIEEE2->clearFlag(MachineInstr::FmNsz);
193+
EXPECT_TRUE(&*MIBFMinNumIEEE == &*MIBFMinNumIEEE2);
194+
}
195+
196+
{
197+
auto MIBFMaxNumIEEE = CSEB.buildFMaxNumIEEE(s32, Copies[0], Copies[1]);
198+
auto MIBFMaxNumIEEE2 = CSEB.buildFMaxNumIEEE(s32, Copies[0], Copies[1]);
199+
EXPECT_TRUE(&*MIBFMaxNumIEEE == &*MIBFMaxNumIEEE2);
200+
201+
auto MIBFMaxNumIEEE3 =
202+
CSEB.buildFMaxNumIEEE(s32, Copies[0], Copies[1], MachineInstr::FmNsz);
203+
EXPECT_FALSE(&*MIBFMaxNumIEEE == &*MIBFMaxNumIEEE3);
204+
205+
MIBFMaxNumIEEE2->setFlag(MachineInstr::FmNsz);
206+
MIBFMaxNumIEEE2->clearFlag(MachineInstr::FmNsz);
207+
EXPECT_TRUE(&*MIBFMaxNumIEEE == &*MIBFMaxNumIEEE2);
208+
}
209+
78210
// Check G_BUILD_VECTOR
79211
Register Reg1 = MRI->createGenericVirtualRegister(s32);
80212
Register Reg2 = MRI->createGenericVirtualRegister(s32);

0 commit comments

Comments
 (0)