Skip to content

Commit 6758786

Browse files
Use dyn_cast, add test.
1 parent b5e8554 commit 6758786

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,8 +1849,8 @@ Instruction *InstCombinerImpl::visitFPTrunc(FPTruncInst &FPT) {
18491849
if (Op && Op->hasOneUse()) {
18501850
IRBuilder<>::FastMathFlagGuard FMFG(Builder);
18511851
FastMathFlags FMF = FPT.getFastMathFlags();
1852-
if (isa<FPMathOperator>(Op))
1853-
FMF &= Op->getFastMathFlags();
1852+
if (auto *FPMO = dyn_cast<FPMathOperator>(Op))
1853+
FMF &= FPMO->getFastMathFlags();
18541854
Builder.setFastMathFlags(FMF);
18551855

18561856
if (match(Op, m_FNeg(m_Value(X)))) {

llvm/test/Transforms/InstCombine/fpcast.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,39 @@ define half @test4_unary_fneg-mixed-fast-2(float %a) {
150150
ret half %c
151151
}
152152

153+
define <2 x half> @test4_unary_fneg-vec-fast(<2 x float> %a) {
154+
; CHECK-LABEL: @test4_unary_fneg-vec-fast(
155+
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc fast <2 x float> [[A:%.*]] to <2 x half>
156+
; CHECK-NEXT: [[C:%.*]] = fneg fast <2 x half> [[TMP1]]
157+
; CHECK-NEXT: ret <2 x half> [[C]]
158+
;
159+
%b = fneg fast <2 x float> %a
160+
%c = fptrunc fast <2 x float> %b to <2 x half>
161+
ret <2 x half> %c
162+
}
163+
164+
define <2 x half> @test4_unary_fneg-vec-mixed-fast-1(<2 x float> %a) {
165+
; CHECK-LABEL: @test4_unary_fneg-vec-mixed-fast-1(
166+
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
167+
; CHECK-NEXT: [[C:%.*]] = fneg <2 x half> [[TMP1]]
168+
; CHECK-NEXT: ret <2 x half> [[C]]
169+
;
170+
%b = fneg <2 x float> %a
171+
%c = fptrunc fast <2 x float> %b to <2 x half>
172+
ret <2 x half> %c
173+
}
174+
175+
define <2 x half> @test4_unary_fneg-vec-mixed-fast-2(<2 x float> %a) {
176+
; CHECK-LABEL: @test4_unary_fneg-vec-mixed-fast-2(
177+
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
178+
; CHECK-NEXT: [[C:%.*]] = fneg <2 x half> [[TMP1]]
179+
; CHECK-NEXT: ret <2 x half> [[C]]
180+
;
181+
%b = fneg fast <2 x float> %a
182+
%c = fptrunc <2 x float> %b to <2 x half>
183+
ret <2 x half> %c
184+
}
185+
153186
define half @test5(float %a, float %b, float %c) {
154187
; CHECK-LABEL: @test5(
155188
; CHECK-NEXT: [[D:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]]

0 commit comments

Comments
 (0)