Skip to content

Attributor: Add denormal-fp-math to attributor-light #79576

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/IPO/Attributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3939,7 +3939,8 @@ static bool runAttributorLightOnFunctions(InformationCache &InfoCache,
&AANoFree::ID, &AANoReturn::ID, &AAMemoryLocation::ID,
&AAMemoryBehavior::ID, &AAUnderlyingObjects::ID, &AANoCapture::ID,
&AAInterFnReachability::ID, &AAIntraFnReachability::ID, &AACallEdges::ID,
&AANoFPClass::ID, &AAMustProgress::ID, &AANonNull::ID});
&AANoFPClass::ID, &AAMustProgress::ID, &AANonNull::ID,
&AADenormalFPMath::ID});
AC.Allowed = &Allowed;
AC.UseLiveness = false;

Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/Attributor/denormal-fp-math.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals --version 2
; RUN: opt -S -passes=attributor < %s | FileCheck %s
; RUN: opt -S -passes=attributor-light < %s | FileCheck %s

; Keep the attribute checks clean by disabling inference of anything else.
declare void @call_of_mystery()
Expand Down
24 changes: 12 additions & 12 deletions llvm/test/Transforms/FunctionAttrs/nocapture.ll
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,22 @@ define void @nc3(ptr %p) {
ret void
}

declare void @external(ptr) readonly nounwind
define void @nc4(ptr %p) {
declare i32 @external(ptr) readonly nounwind
define i32 @nc4(ptr %p) {
; FNATTRS: Function Attrs: nofree nounwind memory(read)
; FNATTRS-LABEL: define void @nc4
; FNATTRS-SAME: (ptr nocapture readonly [[P:%.*]]) #[[ATTR9:[0-9]+]] {
; FNATTRS-NEXT: call void @external(ptr [[P]])
; FNATTRS-NEXT: ret void
; FNATTRS-LABEL: define i32 @nc4
; FNATTRS-SAME: (ptr readonly [[P:%.*]]) #[[ATTR9:[0-9]+]] {
; FNATTRS-NEXT: [[RESULT:%.*]] = call i32 @external(ptr [[P]])
; FNATTRS-NEXT: ret i32 [[RESULT]]
;
; ATTRIBUTOR: Function Attrs: nosync nounwind memory(read)
; ATTRIBUTOR-LABEL: define void @nc4
; ATTRIBUTOR-SAME: (ptr nocapture readonly [[P:%.*]]) #[[ATTR7:[0-9]+]] {
; ATTRIBUTOR-NEXT: call void @external(ptr nocapture readonly [[P]]) #[[ATTR4]]
Copy link
Contributor

@shiltian shiltian Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. Why was the external function call removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the added dead part

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, that makes the test meaningless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why AAIsDead is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because AADenormalFPMathFunction needs to check all the call sites, which needs to know whether a call site is assumed dead or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't need to know that, it can just assume no callsites are dead. The behavior without it makes no sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, AA works in a way that, it assumes all uses are dead at the beginning and then makes uses alive from iteration to iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason if I make it not dead, it also breaks the inference of nocapture: https://godbolt.org/z/oWs5ana4c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would need some kind of no-argument-return thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a way to make the test not-meaningless. If the function doesn't write memory, it has to have a return value to be meaningful. If it has a return value, it's not eligible for nocapture

; ATTRIBUTOR-NEXT: ret void
; ATTRIBUTOR-LABEL: define i32 @nc4
; ATTRIBUTOR-SAME: (ptr readonly [[P:%.*]]) #[[ATTR7:[0-9]+]] {
; ATTRIBUTOR-NEXT: [[RESULT:%.*]] = call i32 @external(ptr [[P]]) #[[ATTR4]]
; ATTRIBUTOR-NEXT: ret i32 [[RESULT]]
;
call void @external(ptr %p)
ret void
%result = call i32 @external(ptr %p)
ret i32 %result
}

define void @nc5(ptr %f, ptr %p) {
Expand Down
15 changes: 0 additions & 15 deletions llvm/test/Transforms/FunctionAttrs/nonnull.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1383,20 +1383,5 @@ define void @PR43833_simple(ptr %0, i32 %1) {
br i1 %11, label %7, label %8
}

define ptr @pr91177_non_inbounds_gep(ptr nonnull %arg) {
; FNATTRS-LABEL: define ptr @pr91177_non_inbounds_gep(
; FNATTRS-SAME: ptr nonnull readnone [[ARG:%.*]]) #[[ATTR0]] {
; FNATTRS-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[ARG]], i64 -8
; FNATTRS-NEXT: ret ptr [[RES]]
;
; ATTRIBUTOR-LABEL: define ptr @pr91177_non_inbounds_gep(
; ATTRIBUTOR-SAME: ptr nofree nonnull readnone [[ARG:%.*]]) #[[ATTR0]] {
; ATTRIBUTOR-NEXT: [[RES:%.*]] = getelementptr i8, ptr [[ARG]], i64 -8
; ATTRIBUTOR-NEXT: ret ptr [[RES]]
;
%res = getelementptr i8, ptr %arg, i64 -8
ret ptr %res
}

attributes #0 = { null_pointer_is_valid }
attributes #1 = { nounwind willreturn}
3 changes: 0 additions & 3 deletions llvm/test/Transforms/FunctionAttrs/nosync.ll
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ define i32 @volatile_load(ptr %0) norecurse nounwind uwtable {
}

; CHECK: Function Attrs: noinline nosync nounwind uwtable
; CHECK-NEXT: declare void @nosync_function()
declare void @nosync_function() noinline nounwind uwtable nosync

define void @call_nosync_function() nounwind uwtable noinline {
Expand All @@ -218,7 +217,6 @@ define void @call_nosync_function() nounwind uwtable noinline {
}

; CHECK: Function Attrs: noinline nounwind uwtable
; CHECK-NEXT: declare void @might_sync()
declare void @might_sync() noinline nounwind uwtable

define void @call_might_sync() nounwind uwtable noinline {
Expand Down Expand Up @@ -280,7 +278,6 @@ define void @convergent_readnone(){
}

; CHECK: Function Attrs: nounwind
; CHECK-NEXT: declare void @llvm.x86.sse2.clflush(ptr)
declare void @llvm.x86.sse2.clflush(ptr)
@a = common global i32 0, align 4

Expand Down
113 changes: 72 additions & 41 deletions llvm/test/Transforms/FunctionAttrs/nounwind.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

; TEST 1
define i32 @foo1() {
; COMMON: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
; COMMON-LABEL: define {{[^@]+}}@foo1
; COMMON-SAME: () #[[ATTR0:[0-9]+]] {
; COMMON-NEXT: ret i32 1
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
; FNATTRS-LABEL: define {{[^@]+}}@foo1
; FNATTRS-SAME: () #[[ATTR0:[0-9]+]] {
; FNATTRS-NEXT: ret i32 1
;
; ATTRIBUTOR: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
; ATTRIBUTOR-LABEL: define {{[^@]+}}@foo1
; ATTRIBUTOR-SAME: () #[[ATTR0:[0-9]+]] {
; ATTRIBUTOR-NEXT: ret i32 1
;
ret i32 1
}
Expand Down Expand Up @@ -70,14 +75,23 @@ define void @call_non_nounwind(){
; }

define i32 @maybe_throw(i1 zeroext %0) {
; COMMON-LABEL: define {{[^@]+}}@maybe_throw
; COMMON-SAME: (i1 zeroext [[TMP0:%.*]]) {
; COMMON-NEXT: br i1 [[TMP0]], label [[TMP2:%.*]], label [[TMP3:%.*]]
; COMMON: 2:
; COMMON-NEXT: tail call void @__cxa_rethrow()
; COMMON-NEXT: unreachable
; COMMON: 3:
; COMMON-NEXT: ret i32 -1
; FNATTRS-LABEL: define {{[^@]+}}@maybe_throw
; FNATTRS-SAME: (i1 zeroext [[TMP0:%.*]]) {
; FNATTRS-NEXT: br i1 [[TMP0]], label [[TMP2:%.*]], label [[TMP3:%.*]]
; FNATTRS: 2:
; FNATTRS-NEXT: tail call void @__cxa_rethrow()
; FNATTRS-NEXT: unreachable
; FNATTRS: 3:
; FNATTRS-NEXT: ret i32 -1
;
; ATTRIBUTOR-LABEL: define {{[^@]+}}@maybe_throw
; ATTRIBUTOR-SAME: (i1 zeroext [[TMP0:%.*]]) {
; ATTRIBUTOR-NEXT: br i1 [[TMP0]], label [[TMP2:%.*]], label [[TMP3:%.*]]
; ATTRIBUTOR: 2:
; ATTRIBUTOR-NEXT: tail call void @__cxa_rethrow()
; ATTRIBUTOR-NEXT: unreachable
; ATTRIBUTOR: 3:
; ATTRIBUTOR-NEXT: ret i32 -1
;
br i1 %0, label %2, label %3

Expand All @@ -101,18 +115,31 @@ declare void @__cxa_rethrow()
; }

define i32 @catch_thing() personality ptr @__gxx_personality_v0 {
; COMMON-LABEL: define {{[^@]+}}@catch_thing() personality ptr @__gxx_personality_v0 {
; COMMON-NEXT: invoke void @__cxa_rethrow()
; COMMON-NEXT: to label [[TMP1:%.*]] unwind label [[TMP2:%.*]]
; COMMON: 1:
; COMMON-NEXT: unreachable
; COMMON: 2:
; COMMON-NEXT: [[TMP3:%.*]] = landingpad { ptr, i32 }
; COMMON-NEXT: catch ptr null
; COMMON-NEXT: [[TMP4:%.*]] = extractvalue { ptr, i32 } [[TMP3]], 0
; COMMON-NEXT: [[TMP5:%.*]] = tail call ptr @__cxa_begin_catch(ptr [[TMP4]])
; COMMON-NEXT: tail call void @__cxa_end_catch()
; COMMON-NEXT: ret i32 -1
; FNATTRS-LABEL: define {{[^@]+}}@catch_thing() personality ptr @__gxx_personality_v0 {
; FNATTRS-NEXT: invoke void @__cxa_rethrow()
; FNATTRS-NEXT: to label [[TMP1:%.*]] unwind label [[TMP2:%.*]]
; FNATTRS: 1:
; FNATTRS-NEXT: unreachable
; FNATTRS: 2:
; FNATTRS-NEXT: [[TMP3:%.*]] = landingpad { ptr, i32 }
; FNATTRS-NEXT: catch ptr null
; FNATTRS-NEXT: [[TMP4:%.*]] = extractvalue { ptr, i32 } [[TMP3]], 0
; FNATTRS-NEXT: [[TMP5:%.*]] = tail call ptr @__cxa_begin_catch(ptr [[TMP4]])
; FNATTRS-NEXT: tail call void @__cxa_end_catch()
; FNATTRS-NEXT: ret i32 -1
;
; ATTRIBUTOR-LABEL: define {{[^@]+}}@catch_thing() personality ptr @__gxx_personality_v0 {
; ATTRIBUTOR-NEXT: invoke void @__cxa_rethrow()
; ATTRIBUTOR-NEXT: to label [[TMP1:%.*]] unwind label [[TMP2:%.*]]
; ATTRIBUTOR: 1:
; ATTRIBUTOR-NEXT: unreachable
; ATTRIBUTOR: 2:
; ATTRIBUTOR-NEXT: [[TMP3:%.*]] = landingpad { ptr, i32 }
; ATTRIBUTOR-NEXT: catch ptr null
; ATTRIBUTOR-NEXT: [[TMP4:%.*]] = extractvalue { ptr, i32 } [[TMP3]], 0
; ATTRIBUTOR-NEXT: [[TMP5:%.*]] = tail call ptr @__cxa_begin_catch(ptr [[TMP4]])
; ATTRIBUTOR-NEXT: tail call void @__cxa_end_catch()
; ATTRIBUTOR-NEXT: ret i32 -1
;
invoke void @__cxa_rethrow() #1
to label %1 unwind label %2
Expand All @@ -130,9 +157,13 @@ define i32 @catch_thing() personality ptr @__gxx_personality_v0 {
}

define i32 @catch_thing_user() {
; COMMON-LABEL: define {{[^@]+}}@catch_thing_user() {
; COMMON-NEXT: [[CATCH_THING_CALL:%.*]] = call i32 @catch_thing()
; COMMON-NEXT: ret i32 [[CATCH_THING_CALL]]
; FNATTRS-LABEL: define {{[^@]+}}@catch_thing_user() {
; FNATTRS-NEXT: [[CATCH_THING_CALL:%.*]] = call i32 @catch_thing()
; FNATTRS-NEXT: ret i32 [[CATCH_THING_CALL]]
;
; ATTRIBUTOR-LABEL: define {{[^@]+}}@catch_thing_user() {
; ATTRIBUTOR-NEXT: [[CATCH_THING_CALL:%.*]] = call i32 @catch_thing()
; ATTRIBUTOR-NEXT: ret i32 [[CATCH_THING_CALL]]
;
%catch_thing_call = call i32 @catch_thing()
ret i32 %catch_thing_call
Expand All @@ -147,10 +178,10 @@ define void @catch_specific_landingpad() personality ptr @__gxx_personality_v0 {
; COMMON-LABEL: define {{[^@]+}}@catch_specific_landingpad
; COMMON-SAME: () #[[ATTR3:[0-9]+]] personality ptr @__gxx_personality_v0 {
; COMMON-NEXT: invoke void @do_throw()
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON: lpad:
; COMMON-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
; COMMON-NEXT: catch ptr @catch_ty
; COMMON-NEXT: catch ptr @catch_ty
; COMMON-NEXT: call void @abort()
; COMMON-NEXT: unreachable
; COMMON: unreachable:
Expand All @@ -174,10 +205,10 @@ define void @catch_all_landingpad() personality ptr @__gxx_personality_v0 {
; COMMON-LABEL: define {{[^@]+}}@catch_all_landingpad
; COMMON-SAME: () #[[ATTR4:[0-9]+]] personality ptr @__gxx_personality_v0 {
; COMMON-NEXT: invoke void @do_throw()
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON: lpad:
; COMMON-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
; COMMON-NEXT: catch ptr null
; COMMON-NEXT: catch ptr null
; COMMON-NEXT: call void @abort()
; COMMON-NEXT: unreachable
; COMMON: unreachable:
Expand All @@ -201,10 +232,10 @@ define void @filter_specific_landingpad() personality ptr @__gxx_personality_v0
; COMMON-LABEL: define {{[^@]+}}@filter_specific_landingpad
; COMMON-SAME: () #[[ATTR3]] personality ptr @__gxx_personality_v0 {
; COMMON-NEXT: invoke void @do_throw()
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON: lpad:
; COMMON-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
; COMMON-NEXT: filter [1 x ptr] [ptr @catch_ty]
; COMMON-NEXT: filter [1 x ptr] [ptr @catch_ty]
; COMMON-NEXT: call void @abort()
; COMMON-NEXT: unreachable
; COMMON: unreachable:
Expand All @@ -228,10 +259,10 @@ define void @filter_none_landingpad() personality ptr @__gxx_personality_v0 {
; COMMON-LABEL: define {{[^@]+}}@filter_none_landingpad
; COMMON-SAME: () #[[ATTR4]] personality ptr @__gxx_personality_v0 {
; COMMON-NEXT: invoke void @do_throw()
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON: lpad:
; COMMON-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
; COMMON-NEXT: filter [0 x ptr] zeroinitializer
; COMMON-NEXT: filter [0 x ptr] zeroinitializer
; COMMON-NEXT: call void @abort()
; COMMON-NEXT: unreachable
; COMMON: unreachable:
Expand All @@ -255,10 +286,10 @@ define void @cleanup_landingpad() personality ptr @__gxx_personality_v0 {
; COMMON-LABEL: define {{[^@]+}}@cleanup_landingpad
; COMMON-SAME: () #[[ATTR3]] personality ptr @__gxx_personality_v0 {
; COMMON-NEXT: invoke void @do_throw()
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[LPAD:%.*]]
; COMMON: lpad:
; COMMON-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
; COMMON-NEXT: cleanup
; COMMON-NEXT: cleanup
; COMMON-NEXT: call void @abort()
; COMMON-NEXT: unreachable
; COMMON: unreachable:
Expand All @@ -282,7 +313,7 @@ define void @cleanuppad() personality ptr @__gxx_personality_v0 {
; FNATTRS-LABEL: define {{[^@]+}}@cleanuppad
; FNATTRS-SAME: () #[[ATTR3]] personality ptr @__gxx_personality_v0 {
; FNATTRS-NEXT: invoke void @do_throw()
; FNATTRS-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CPAD:%.*]]
; FNATTRS-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CPAD:%.*]]
; FNATTRS: cpad:
; FNATTRS-NEXT: [[CP:%.*]] = cleanuppad within none []
; FNATTRS-NEXT: call void @abort()
Expand All @@ -294,7 +325,7 @@ define void @cleanuppad() personality ptr @__gxx_personality_v0 {
; ATTRIBUTOR-LABEL: define {{[^@]+}}@cleanuppad
; ATTRIBUTOR-SAME: () #[[ATTR4]] personality ptr @__gxx_personality_v0 {
; ATTRIBUTOR-NEXT: invoke void @do_throw()
; ATTRIBUTOR-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CPAD:%.*]]
; ATTRIBUTOR-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CPAD:%.*]]
; ATTRIBUTOR: cpad:
; ATTRIBUTOR-NEXT: [[CP:%.*]] = cleanuppad within none []
; ATTRIBUTOR-NEXT: call void @abort()
Expand All @@ -319,7 +350,7 @@ define void @catchswitch_cleanuppad() personality ptr @__gxx_personality_v0 {
; FNATTRS-LABEL: define {{[^@]+}}@catchswitch_cleanuppad
; FNATTRS-SAME: () #[[ATTR3]] personality ptr @__gxx_personality_v0 {
; FNATTRS-NEXT: invoke void @do_throw()
; FNATTRS-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CS:%.*]]
; FNATTRS-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CS:%.*]]
; FNATTRS: cs:
; FNATTRS-NEXT: [[TOK:%.*]] = catchswitch within none [label %catch] unwind label [[CPAD:%.*]]
; FNATTRS: catch:
Expand All @@ -337,7 +368,7 @@ define void @catchswitch_cleanuppad() personality ptr @__gxx_personality_v0 {
; ATTRIBUTOR-LABEL: define {{[^@]+}}@catchswitch_cleanuppad
; ATTRIBUTOR-SAME: () #[[ATTR4]] personality ptr @__gxx_personality_v0 {
; ATTRIBUTOR-NEXT: invoke void @do_throw()
; ATTRIBUTOR-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CS:%.*]]
; ATTRIBUTOR-NEXT: to label [[UNREACHABLE:%.*]] unwind label [[CS:%.*]]
; ATTRIBUTOR: cs:
; ATTRIBUTOR-NEXT: [[TOK:%.*]] = catchswitch within none [label %catch] unwind label [[CPAD:%.*]]
; ATTRIBUTOR: catch:
Expand Down