-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clang: Add __builtin_elementwise_rint and nearbyint
These are basically the same thing and only differ for strictfp, so add both for future proofing. Note all the elementwise functions are currently broken for strictfp, and use non-constrained ops. Add a test that demonstrates this, but doesn't attempt to fix it.
- Loading branch information
Showing
9 changed files
with
344 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2 | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -frounding-math -ffp-exception-behavior=strict -O2 -emit-llvm -o - %s | FileCheck %s | ||
|
||
// FIXME: This demonstrates elementwise builtins are broken for strictfp and | ||
// produce unconstrained intrinsics | ||
|
||
typedef float float4 __attribute__((ext_vector_type(4))); | ||
|
||
// Sanity check we're getting constrained ops for a non-builtin. | ||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z11strict_faddDv4_fS_ | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ADD:%.*]] = tail call <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float> [[A]], <4 x float> [[B]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4:[0-9]+]] | ||
// CHECK-NEXT: ret <4 x float> [[ADD]] | ||
// | ||
float4 strict_fadd(float4 a, float4 b) { | ||
return a + b; | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_absDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_ABS:%.*]] = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_ABS]] | ||
// | ||
float4 strict_elementwise_abs(float4 a) { | ||
return __builtin_elementwise_abs(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_maxDv4_fS_ | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_MAX:%.*]] = tail call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_MAX]] | ||
// | ||
float4 strict_elementwise_max(float4 a, float4 b) { | ||
return __builtin_elementwise_max(a, b); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_minDv4_fS_ | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_MIN:%.*]] = tail call <4 x float> @llvm.minnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_MIN]] | ||
// | ||
float4 strict_elementwise_min(float4 a, float4 b) { | ||
return __builtin_elementwise_min(a, b); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_ceilDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_CEIL:%.*]] = tail call <4 x float> @llvm.ceil.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_CEIL]] | ||
// | ||
float4 strict_elementwise_ceil(float4 a) { | ||
return __builtin_elementwise_ceil(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_cosDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_COS:%.*]] = tail call <4 x float> @llvm.cos.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_COS]] | ||
// | ||
float4 strict_elementwise_cos(float4 a) { | ||
return __builtin_elementwise_cos(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_expDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_EXP:%.*]] = tail call <4 x float> @llvm.exp.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_EXP]] | ||
// | ||
float4 strict_elementwise_exp(float4 a) { | ||
return __builtin_elementwise_exp(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_exp2Dv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_EXP2:%.*]] = tail call <4 x float> @llvm.exp2.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_EXP2]] | ||
// | ||
float4 strict_elementwise_exp2(float4 a) { | ||
return __builtin_elementwise_exp2(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_floorDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_FLOOR:%.*]] = tail call <4 x float> @llvm.floor.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_FLOOR]] | ||
// | ||
float4 strict_elementwise_floor(float4 a) { | ||
return __builtin_elementwise_floor(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_logDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_LOG:%.*]] = tail call <4 x float> @llvm.log.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_LOG]] | ||
// | ||
float4 strict_elementwise_log(float4 a) { | ||
return __builtin_elementwise_log(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_log2Dv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_LOG2:%.*]] = tail call <4 x float> @llvm.log2.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_LOG2]] | ||
// | ||
float4 strict_elementwise_log2(float4 a) { | ||
return __builtin_elementwise_log2(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_log10Dv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_LOG2:%.*]] = tail call <4 x float> @llvm.log2.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_LOG2]] | ||
// | ||
float4 strict_elementwise_log10(float4 a) { | ||
return __builtin_elementwise_log2(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z28strict_elementwise_roundevenDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_ROUNDEVEN:%.*]] = tail call <4 x float> @llvm.roundeven.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_ROUNDEVEN]] | ||
// | ||
float4 strict_elementwise_roundeven(float4 a) { | ||
return __builtin_elementwise_roundeven(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_roundDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_ROUND:%.*]] = tail call <4 x float> @llvm.round.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_ROUND]] | ||
// | ||
float4 strict_elementwise_round(float4 a) { | ||
return __builtin_elementwise_round(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_rintDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_RINT:%.*]] = tail call <4 x float> @llvm.rint.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_RINT]] | ||
// | ||
float4 strict_elementwise_rint(float4 a) { | ||
return __builtin_elementwise_rint(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z28strict_elementwise_nearbyintDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_NEARBYINT:%.*]] = tail call <4 x float> @llvm.nearbyint.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_NEARBYINT]] | ||
// | ||
float4 strict_elementwise_nearbyint(float4 a) { | ||
return __builtin_elementwise_nearbyint(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_sinDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_SIN:%.*]] = tail call <4 x float> @llvm.sin.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_SIN]] | ||
// | ||
float4 strict_elementwise_sin(float4 a) { | ||
return __builtin_elementwise_sin(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_truncDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_TRUNC:%.*]] = tail call <4 x float> @llvm.trunc.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_TRUNC]] | ||
// | ||
float4 strict_elementwise_trunc(float4 a) { | ||
return __builtin_elementwise_trunc(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z31strict_elementwise_canonicalizeDv4_f | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[ELT_CANONICALIZE:%.*]] = tail call <4 x float> @llvm.canonicalize.v4f32(<4 x float> [[A]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[ELT_CANONICALIZE]] | ||
// | ||
float4 strict_elementwise_canonicalize(float4 a) { | ||
return __builtin_elementwise_canonicalize(a); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z27strict_elementwise_copysignDv4_fS_ | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[TMP0:%.*]] = tail call <4 x float> @llvm.copysign.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[TMP0]] | ||
// | ||
float4 strict_elementwise_copysign(float4 a, float4 b) { | ||
return __builtin_elementwise_copysign(a, b); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_fmaDv4_fS_S_ | ||
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]], <4 x float> noundef [[C:%.*]]) local_unnamed_addr #[[ATTR2]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[TMP0:%.*]] = tail call <4 x float> @llvm.fma.v4f32(<4 x float> [[A]], <4 x float> [[B]], <4 x float> [[C]]) #[[ATTR4]] | ||
// CHECK-NEXT: ret <4 x float> [[TMP0]] | ||
// | ||
float4 strict_elementwise_fma(float4 a, float4 b, float4 c) { | ||
return __builtin_elementwise_fma(a, b, c); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.