Skip to content

Commit 0a045c9

Browse files
authored
[AArch64][GISEL] Consider fcmp true and fcmp false in cond code selection (#86972) (#91580)
Fixes #86917 `FCMP_TRUE` and `FCMP_FALSE` were previously not considered and we ended up in an llvm_unreachable assertion.
1 parent 4a28f8e commit 0a045c9

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

llvm/lib/Target/AArch64/GISel/AArch64GlobalISelUtils.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ void AArch64GISelUtils::changeFCMPPredToAArch64CC(
147147
case CmpInst::FCMP_UNE:
148148
CondCode = AArch64CC::NE;
149149
break;
150+
case CmpInst::FCMP_TRUE:
151+
CondCode = AArch64CC::AL;
152+
break;
153+
case CmpInst::FCMP_FALSE:
154+
CondCode = AArch64CC::NV;
155+
break;
150156
}
151157
}
152158

llvm/test/CodeGen/AArch64/GlobalISel/select.mir

+20
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ registers:
183183
- { id: 5, class: gpr }
184184
- { id: 6, class: gpr }
185185
- { id: 7, class: gpr }
186+
- { id: 8, class: fpr }
187+
- { id: 9, class: gpr }
188+
- { id: 10, class: fpr }
189+
- { id: 11, class: gpr }
190+
- { id: 12, class: gpr }
191+
- { id: 13, class: gpr }
192+
- { id: 14, class: gpr }
193+
- { id: 15, class: gpr }
186194

187195
# CHECK: body:
188196
# CHECK: nofpexcept FCMPSrr %0, %0, implicit-def $nzcv
@@ -209,6 +217,18 @@ body: |
209217
%7(s32) = G_ANYEXT %5
210218
$w0 = COPY %7(s32)
211219
220+
%8(s32) = COPY $s0
221+
%9(s32) = G_FCMP floatpred(true), %8, %8
222+
%12(s8) = G_TRUNC %9(s32)
223+
%14(s32) = G_ANYEXT %12
224+
$w0 = COPY %14(s32)
225+
226+
%10(s64) = COPY $d0
227+
%11(s32) = G_FCMP floatpred(false), %10, %10
228+
%13(s8) = G_TRUNC %11(s32)
229+
%15(s32) = G_ANYEXT %13
230+
$w0 = COPY %15(s32)
231+
212232
...
213233

214234
---

llvm/test/CodeGen/AArch64/neon-compare-instructions.ll

+89
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,95 @@ define <2 x i64> @fcmune2xdouble(<2 x double> %A, <2 x double> %B) {
28702870
ret <2 x i64> %tmp4
28712871
}
28722872

2873+
define <2 x i32> @fcmal2xfloat(<2 x float> %A, <2 x float> %B) {
2874+
; CHECK-SD-LABEL: fcmal2xfloat:
2875+
; CHECK-SD: // %bb.0:
2876+
; CHECK-SD-NEXT: movi v0.2d, #0xffffffffffffffff
2877+
; CHECK-SD-NEXT: ret
2878+
;
2879+
; CHECK-GI-LABEL: fcmal2xfloat:
2880+
; CHECK-GI: // %bb.0:
2881+
; CHECK-GI-NEXT: movi v0.2s, #1
2882+
; CHECK-GI-NEXT: shl v0.2s, v0.2s, #31
2883+
; CHECK-GI-NEXT: sshr v0.2s, v0.2s, #31
2884+
; CHECK-GI-NEXT: ret
2885+
%tmp3 = fcmp true <2 x float> %A, %B
2886+
%tmp4 = sext <2 x i1> %tmp3 to <2 x i32>
2887+
ret <2 x i32> %tmp4
2888+
}
2889+
2890+
define <4 x i32> @fcmal4xfloat(<4 x float> %A, <4 x float> %B) {
2891+
; CHECK-SD-LABEL: fcmal4xfloat:
2892+
; CHECK-SD: // %bb.0:
2893+
; CHECK-SD-NEXT: movi v0.2d, #0xffffffffffffffff
2894+
; CHECK-SD-NEXT: ret
2895+
;
2896+
; CHECK-GI-LABEL: fcmal4xfloat:
2897+
; CHECK-GI: // %bb.0:
2898+
; CHECK-GI-NEXT: movi v0.2s, #1
2899+
; CHECK-GI-NEXT: mov v0.d[1], v0.d[0]
2900+
; CHECK-GI-NEXT: shl v0.4s, v0.4s, #31
2901+
; CHECK-GI-NEXT: sshr v0.4s, v0.4s, #31
2902+
; CHECK-GI-NEXT: ret
2903+
%tmp3 = fcmp true <4 x float> %A, %B
2904+
%tmp4 = sext <4 x i1> %tmp3 to <4 x i32>
2905+
ret <4 x i32> %tmp4
2906+
}
2907+
define <2 x i64> @fcmal2xdouble(<2 x double> %A, <2 x double> %B) {
2908+
; CHECK-SD-LABEL: fcmal2xdouble:
2909+
; CHECK-SD: // %bb.0:
2910+
; CHECK-SD-NEXT: movi v0.2d, #0xffffffffffffffff
2911+
; CHECK-SD-NEXT: ret
2912+
;
2913+
; CHECK-GI-LABEL: fcmal2xdouble:
2914+
; CHECK-GI: // %bb.0:
2915+
; CHECK-GI-NEXT: adrp x8, .LCPI221_0
2916+
; CHECK-GI-NEXT: ldr q0, [x8, :lo12:.LCPI221_0]
2917+
; CHECK-GI-NEXT: shl v0.2d, v0.2d, #63
2918+
; CHECK-GI-NEXT: sshr v0.2d, v0.2d, #63
2919+
; CHECK-GI-NEXT: ret
2920+
%tmp3 = fcmp true <2 x double> %A, %B
2921+
%tmp4 = sext <2 x i1> %tmp3 to <2 x i64>
2922+
ret <2 x i64> %tmp4
2923+
}
2924+
2925+
define <2 x i32> @fcmnv2xfloat(<2 x float> %A, <2 x float> %B) {
2926+
; CHECK-LABEL: fcmnv2xfloat:
2927+
; CHECK: // %bb.0:
2928+
; CHECK-NEXT: movi v0.2d, #0000000000000000
2929+
; CHECK-NEXT: ret
2930+
%tmp3 = fcmp false <2 x float> %A, %B
2931+
%tmp4 = sext <2 x i1> %tmp3 to <2 x i32>
2932+
ret <2 x i32> %tmp4
2933+
}
2934+
2935+
define <4 x i32> @fcmnv4xfloat(<4 x float> %A, <4 x float> %B) {
2936+
; CHECK-SD-LABEL: fcmnv4xfloat:
2937+
; CHECK-SD: // %bb.0:
2938+
; CHECK-SD-NEXT: movi v0.2d, #0000000000000000
2939+
; CHECK-SD-NEXT: ret
2940+
;
2941+
; CHECK-GI-LABEL: fcmnv4xfloat:
2942+
; CHECK-GI: // %bb.0:
2943+
; CHECK-GI-NEXT: movi v0.2d, #0000000000000000
2944+
; CHECK-GI-NEXT: mov v0.d[1], v0.d[0]
2945+
; CHECK-GI-NEXT: shl v0.4s, v0.4s, #31
2946+
; CHECK-GI-NEXT: sshr v0.4s, v0.4s, #31
2947+
; CHECK-GI-NEXT: ret
2948+
%tmp3 = fcmp false <4 x float> %A, %B
2949+
%tmp4 = sext <4 x i1> %tmp3 to <4 x i32>
2950+
ret <4 x i32> %tmp4
2951+
}
2952+
define <2 x i64> @fcmnv2xdouble(<2 x double> %A, <2 x double> %B) {
2953+
; CHECK-LABEL: fcmnv2xdouble:
2954+
; CHECK: // %bb.0:
2955+
; CHECK-NEXT: movi v0.2d, #0000000000000000
2956+
; CHECK-NEXT: ret
2957+
%tmp3 = fcmp false <2 x double> %A, %B
2958+
%tmp4 = sext <2 x i1> %tmp3 to <2 x i64>
2959+
ret <2 x i64> %tmp4
2960+
}
2961+
28732962
define <2 x i32> @fcmoeqz2xfloat(<2 x float> %A) {
28742963
; CHECK-LABEL: fcmoeqz2xfloat:
28752964
; CHECK: // %bb.0:

0 commit comments

Comments
 (0)