Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FuncSpec]Fix assertion failure when value is not added to solver
This patch improves the fix in D110529 to prevent from crashing on value with byval attribute that is not added in SCCP solver. Authored-by: sinan.lin@linux.alibaba.com Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D126355
- Loading branch information
Bin Cheng
committed
Jun 10, 2022
1 parent
f8aba99
commit 8b360c6
Showing
4 changed files
with
85 additions
and
13 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
32 changes: 32 additions & 0 deletions
32
llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression4.ll
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,32 @@ | ||
; RUN: opt -function-specialization -force-function-specialization -S < %s | FileCheck %s | ||
|
||
; Check that we don't crash and specialise on a function call with byval attribute. | ||
|
||
; CHECK-NOT: wombat.{{[0-9]+}} | ||
|
||
declare i32* @quux() | ||
declare i32* @eggs() | ||
|
||
define i32 @main() { | ||
; CHECK: bb: | ||
; CHECK-NEXT: tail call void @wombat(i8* undef, i64 undef, i64 undef, i32* byval(i32) bitcast (i32* ()* @quux to i32*)) | ||
; CHECK-NEXT: tail call void @wombat(i8* undef, i64 undef, i64 undef, i32* byval(i32) bitcast (i32* ()* @eggs to i32*)) | ||
; CHECK-NEXT: ret i32 undef | ||
; | ||
bb: | ||
tail call void @wombat(i8* undef, i64 undef, i64 undef, i32* byval(i32) bitcast (i32* ()* @quux to i32*)) | ||
tail call void @wombat(i8* undef, i64 undef, i64 undef, i32* byval(i32) bitcast (i32* ()* @eggs to i32*)) | ||
ret i32 undef | ||
} | ||
|
||
define internal void @wombat(i8* %arg, i64 %arg1, i64 %arg2, i32* byval(i32) %func) { | ||
; CHECK: bb2: | ||
; CHECK-NEXT: [[FUNPTR:%.*]] = bitcast i32* %func to i32* (i8*, i8*)* | ||
; CHECK-NEXT: [[TMP:%.*]] = tail call i32* [[FUNPTR]](i8* undef, i8* undef) | ||
; CHECK-NEXT: ret void | ||
; | ||
bb2: | ||
%mycall = bitcast i32* %func to i32* (i8*, i8*)* | ||
%tmp = tail call i32* %mycall(i8* undef, i8* undef) | ||
ret void | ||
} |
46 changes: 46 additions & 0 deletions
46
llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression5.ll
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,46 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -function-specialization -force-function-specialization -func-specialization-on-address -S < %s | FileCheck %s | ||
|
||
; Check that we don't crash and specialise on a scalar global variable with byval attribute. | ||
|
||
; CHECK-NOT: wombat.{{[0-9]+}} | ||
|
||
%struct.pluto = type { %struct.spam } | ||
%struct.quux = type { i16 } | ||
%struct.spam = type { i16 } | ||
|
||
@global.5 = external dso_local global i128 | ||
@global.12 = external global %struct.quux | ||
|
||
define internal i16 @wobble(%struct.quux* %arg, i16 %arg1, i128* byval(i128) %arg2, %struct.quux* %arg3) { | ||
; CHECK-LABEL: @wobble( | ||
; CHECK-NEXT: bb: | ||
; CHECK-NEXT: [[TMP34:%.*]] = bitcast i128* [[ARG2:%.*]] to i16* | ||
; CHECK-NEXT: unreachable | ||
; | ||
bb: | ||
%tmp34 = bitcast i128* %arg2 to i16* | ||
unreachable | ||
} | ||
|
||
define internal i16 @snork() { | ||
; CHECK-LABEL: @snork( | ||
; CHECK-NEXT: bb4: | ||
; CHECK-NEXT: [[TMP35:%.*]] = call i16 @wobble(%struct.quux* undef, i16 2, i128* byval(i128) @global.5, %struct.quux* @global.12) | ||
; CHECK-NEXT: unreachable | ||
; | ||
bb4: | ||
%tmp35 = call i16 @wobble(%struct.quux* undef, i16 2, i128* byval(i128) @global.5, %struct.quux* @global.12) | ||
unreachable | ||
} | ||
|
||
define i16 @main() { | ||
; CHECK-LABEL: @main( | ||
; CHECK-NEXT: bb: | ||
; CHECK-NEXT: [[TMP:%.*]] = call i16 @snork() | ||
; CHECK-NEXT: unreachable | ||
; | ||
bb: | ||
%tmp = call i16 @snork() | ||
unreachable | ||
} |