-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[llvm] Add support for llvm IR atomicrmw fminimum/fmaximum instructions #136759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fbb1c0e
f0ff4d6
b3ab5b7
9d97625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,3 +43,170 @@ define float @test_atomicrmw_fsub_f32(ptr %ptr, float %value) { | |
| ret float %res | ||
| } | ||
|
|
||
| define float @atomicrmw_fmin_float(ptr %ptr, float %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fmin_float( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[PTR:%.*]], align 4 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call float @llvm.minnum.f32(float [[LOADED]], float [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast float [[TMP2]] to i32 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst, align 4 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret float [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fmin ptr %ptr, float %value seq_cst | ||
| ret float %res | ||
| } | ||
|
|
||
| define float @atomicrmw_fmax_float(ptr %ptr, float %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fmax_float( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[PTR:%.*]], align 4 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call float @llvm.maxnum.f32(float [[LOADED]], float [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast float [[TMP2]] to i32 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst, align 4 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret float [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fmax ptr %ptr, float %value seq_cst | ||
| ret float %res | ||
| } | ||
|
|
||
| define double @atomicrmw_fmin_double(ptr %ptr, double %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fmin_double( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[PTR:%.*]], align 8 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.minnum.f64(double [[LOADED]], double [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast double [[TMP2]] to i64 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst, align 8 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret double [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fmin ptr %ptr, double %value seq_cst | ||
| ret double %res | ||
| } | ||
|
|
||
| define double @atomicrmw_fmax_double(ptr %ptr, double %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fmax_double( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[PTR:%.*]], align 8 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.maxnum.f64(double [[LOADED]], double [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast double [[TMP2]] to i64 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst, align 8 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret double [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fmax ptr %ptr, double %value seq_cst | ||
| ret double %res | ||
| } | ||
|
|
||
| define float @atomicrmw_fminimum_float(ptr %ptr, float %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fminimum_float( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[PTR:%.*]], align 4 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call float @llvm.minimum.f32(float [[LOADED]], float [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast float [[TMP2]] to i32 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst, align 4 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret float [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fminimum ptr %ptr, float %value seq_cst | ||
| ret float %res | ||
| } | ||
|
|
||
| define float @atomicrmw_fmaximum_float(ptr %ptr, float %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fmaximum_float( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[PTR:%.*]], align 4 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call float @llvm.maximum.f32(float [[LOADED]], float [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast float [[TMP2]] to i32 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst, align 4 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret float [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fmaximum ptr %ptr, float %value seq_cst | ||
| ret float %res | ||
| } | ||
|
|
||
| define double @atomicrmw_fminimum_double(ptr %ptr, double %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fminimum_double( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[PTR:%.*]], align 8 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.minimum.f64(double [[LOADED]], double [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast double [[TMP2]] to i64 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst, align 8 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret double [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fminimum ptr %ptr, double %value seq_cst | ||
| ret double %res | ||
| } | ||
|
|
||
| define double @atomicrmw_fmaximum_double(ptr %ptr, double %value) { | ||
| ; CHECK-LABEL: @atomicrmw_fmaximum_double( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[PTR:%.*]], align 8 | ||
| ; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]] | ||
| ; CHECK: atomicrmw.start: | ||
| ; CHECK-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ] | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.maximum.f64(double [[LOADED]], double [[VALUE:%.*]]) | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = bitcast double [[TMP2]] to i64 | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64 | ||
| ; CHECK-NEXT: [[TMP5:%.*]] = cmpxchg ptr [[PTR]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst, align 8 | ||
| ; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1 | ||
| ; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0 | ||
| ; CHECK-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double | ||
| ; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]] | ||
| ; CHECK: atomicrmw.end: | ||
| ; CHECK-NEXT: ret double [[TMP6]] | ||
| ; | ||
| %res = atomicrmw fmaximum ptr %ptr, double %value seq_cst | ||
| ret double %res | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test a vector case like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, now added. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,3 +100,24 @@ define float @fminimum() { | |
| ret float %j | ||
| ; CHECK: ret float [[INST]] | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test a vector case too, e.g
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion, done. |
||
|
|
||
| define <2 x half> @fmaximum_2xhalf(<2 x half> %val) { | ||
| ; CHECK-LABEL: @fmaximum_2xhalf( | ||
| %i = alloca <2 x half>, align 4 | ||
| %j = atomicrmw fmaximum ptr %i, <2 x half> %val monotonic | ||
| ; CHECK: [[INST:%[a-z0-9]+]] = load | ||
| ; CHECK-NEXT: call <2 x half> @llvm.maximum.v2f16 | ||
| ; CHECK-NEXT: store | ||
| ret <2 x half> %j | ||
| } | ||
|
|
||
| define <2 x half> @fminimum_2xhalf(<2 x half> %val) { | ||
| ; CHECK-LABEL: @fminimum_2xhalf( | ||
| %i = alloca <2 x half>, align 4 | ||
| %j = atomicrmw fminimum ptr %i, <2 x half> %val monotonic | ||
| ; CHECK: [[INST:%[a-z0-9]+]] = load | ||
| ; CHECK-NEXT: call <2 x half> @llvm.minimum.v2f16 | ||
| ; CHECK-NEXT: store | ||
| ret <2 x half> %j | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test half and bfloat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, now added.