Skip to content

Commit ce2cb0f

Browse files
committedSep 9, 2019
[X86] Allow _MM_FROUND_CUR_DIRECTION and _MM_FROUND_NO_EXC to be used together on instructions that only support SAE and not embedded rounding.
Current for SAE instructions we only allow _MM_FROUND_CUR_DIRECTION(bit 2) or _MM_FROUND_NO_EXC(bit 3) to be used as the immediate passed to the inrinsics. But these instructions don't perform rounding so _MM_FROUND_CUR_DIRECTION is just sort of a default placeholder when you don't want to suppress exceptions. Using _MM_FROUND_NO_EXC by itself is really bit equivalent to (_MM_FROUND_NO_EXC | _MM_FROUND_TO_NEAREST_INT) since _MM_FROUND_TO_NEAREST_INT is 0. Since we aren't rounding on these instructions we should also accept (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC) as equivalent to (_MM_FROUND_NO_EXC). icc allows this, but gcc does not. Differential Revision: https://reviews.llvm.org/D67289 llvm-svn: 371430
1 parent a85d9ef commit ce2cb0f

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed
 

‎clang/lib/Sema/SemaChecking.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -3546,9 +3546,11 @@ bool Sema::CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall) {
35463546

35473547
// Make sure rounding mode is either ROUND_CUR_DIRECTION or ROUND_NO_EXC bit
35483548
// is set. If the intrinsic has rounding control(bits 1:0), make sure its only
3549-
// combined with ROUND_NO_EXC.
3549+
// combined with ROUND_NO_EXC. If the intrinsic does not have rounding
3550+
// control, allow ROUND_NO_EXC and ROUND_CUR_DIRECTION together.
35503551
if (Result == 4/*ROUND_CUR_DIRECTION*/ ||
35513552
Result == 8/*ROUND_NO_EXC*/ ||
3553+
(!HasRC && Result == 12/*ROUND_CUR_DIRECTION|ROUND_NO_EXC*/) ||
35523554
(HasRC && Result.getZExtValue() >= 8 && Result.getZExtValue() <= 11))
35533555
return false;
35543556

‎clang/test/Sema/builtins-x86.c

+13
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ __mmask16 test__builtin_ia32_cmpps512_mask_rounding(__m512 __a, __m512 __b, __mm
8181
return __builtin_ia32_cmpps512_mask(__a, __b, 0, __u, 0); // expected-error {{invalid rounding argument}}
8282
}
8383

84+
// Make sure we allow 4(CUR_DIRECTION), 8(NO_EXC), and 12(CUR_DIRECTION|NOEXC) for SAE arguments.
85+
__mmask16 test__builtin_ia32_cmpps512_mask_rounding_cur_dir(__m512 __a, __m512 __b, __mmask16 __u) {
86+
return __builtin_ia32_cmpps512_mask(__a, __b, 0, __u, 4); // no-error
87+
}
88+
89+
__mmask16 test__builtin_ia32_cmpps512_mask_rounding_sae1(__m512 __a, __m512 __b, __mmask16 __u) {
90+
return __builtin_ia32_cmpps512_mask(__a, __b, 0, __u, 8); // no-error
91+
}
92+
93+
__mmask16 test__builtin_ia32_cmpps512_mask_rounding_sae2(__m512 __a, __m512 __b, __mmask16 __u) {
94+
return __builtin_ia32_cmpps512_mask(__a, __b, 0, __u, 12); // no-error
95+
}
96+
8497
__m512 test__builtin_ia32_getmantps512_mask(__m512 a, __m512 b) {
8598
return __builtin_ia32_getmantps512_mask(a, 0, b, (__mmask16)-1, 10); // expected-error {{invalid rounding argument}}
8699
}

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -22706,8 +22706,16 @@ SDValue X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
2270622706
return false;
2270722707
};
2270822708
auto isRoundModeSAE = [](SDValue Rnd) {
22709-
if (auto *C = dyn_cast<ConstantSDNode>(Rnd))
22710-
return C->getAPIntValue() == X86::STATIC_ROUNDING::NO_EXC;
22709+
if (auto *C = dyn_cast<ConstantSDNode>(Rnd)) {
22710+
unsigned RC = C->getZExtValue();
22711+
if (RC & X86::STATIC_ROUNDING::NO_EXC) {
22712+
// Clear the NO_EXC bit and check remaining bits.
22713+
RC ^= X86::STATIC_ROUNDING::NO_EXC;
22714+
// As a convenience we allow no other bits or explicitly
22715+
// current direction.
22716+
return RC == 0 || RC == X86::STATIC_ROUNDING::CUR_DIRECTION;
22717+
}
22718+
}
2271122719

2271222720
return false;
2271322721
};

‎llvm/test/CodeGen/X86/avx512-intrinsics.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ define <8 x double> @test_getexp_round_pd_512(<8 x double> %a0) {
755755
; CHECK: # %bb.0:
756756
; CHECK-NEXT: vgetexppd {sae}, %zmm0, %zmm0
757757
; CHECK-NEXT: ret{{[l|q]}}
758-
%res = call <8 x double> @llvm.x86.avx512.mask.getexp.pd.512(<8 x double> %a0, <8 x double> zeroinitializer, i8 -1, i32 8)
758+
%res = call <8 x double> @llvm.x86.avx512.mask.getexp.pd.512(<8 x double> %a0, <8 x double> zeroinitializer, i8 -1, i32 12)
759759
ret <8 x double> %res
760760
}
761761
declare <8 x double> @llvm.x86.avx512.mask.getexp.pd.512(<8 x double>, <8 x double>, i8, i32) nounwind readnone

0 commit comments

Comments
 (0)