-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[X86] Fix 32-bit immediate assertion and convert into backend error #123872
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
wesleywiser
wants to merge
1
commit into
llvm:main
Choose a base branch
from
wesleywiser:fix_32_bit_immediate_assert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -965,11 +965,10 @@ X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, | |
} | ||
|
||
if (MI.getOperand(FIOperandNum+3).isImm()) { | ||
// Offset is a 32-bit integer. | ||
int Imm = (int)(MI.getOperand(FIOperandNum + 3).getImm()); | ||
int Offset = FIOffset + Imm; | ||
assert((!Is64Bit || isInt<32>((long long)FIOffset + Imm)) && | ||
"Requesting 64-bit offset in 32-bit immediate!"); | ||
int64_t Imm = MI.getOperand(FIOperandNum + 3).getImm(); | ||
int Offset = FIOffset + (int)Imm; | ||
if (!Is64Bit && !isInt<32>((int64_t)FIOffset + Imm)) | ||
MI.emitGenericError("requesting 64-bit offset in 32-bit immediate"); | ||
if (Offset != 0 || !tryOptimizeLEAtoMOV(II)) | ||
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. If Imm == -FIOffset wouldn't that mean the operand isn't correctly set to zero? |
||
MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset); | ||
} else { | ||
|
This file contains hidden or 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,17 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s -mtriple=x86_64 -O=0 | FileCheck %s | ||
@G = global i8 0 | ||
|
||
; Regression test for #113856 - incorrect FastISel assert | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
define dso_local i32 @main() #0 { | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-LABEL: main: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: movl $0, {{[0-9]+}}(%rsp) | ||
; CHECK-NEXT: xorl %eax, %eax | ||
; CHECK-NEXT: retq | ||
%1 = alloca i32, align 4 | ||
%G = getelementptr i8, ptr %1, i32 -2147483648 | ||
store i32 0, ptr %G, align 4 | ||
ret i32 0 | ||
} |
This file contains hidden or 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,79 @@ | ||
; RUN: not llc < %s -mtriple=i686 -filetype=null 2>&1 | FileCheck %s -check-prefix=ERR-i686 | ||
; RUN: llc < %s -mtriple=x86_64 | FileCheck %s -check-prefix=x86_64 | ||
|
||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; Regression test for #121932, #113856, #106352, #69365, #25051 which are caused by | ||
; an incorrectly written assertion for 64-bit offsets when compiling for 32-bit X86. | ||
|
||
define i32 @main() #0 { | ||
; ERR-i686: error: <unknown>:0:0: requesting 64-bit offset in 32-bit immediate | ||
; | ||
; x86_64-LABEL: main: | ||
; x86_64: # %bb.0: # %entry | ||
; x86_64-NEXT: movl $4294967176, %eax # imm = 0xFFFFFF88 | ||
; x86_64-NEXT: subq %rax, %rsp | ||
; x86_64-NEXT: .cfi_def_cfa_offset 4294967184 | ||
; x86_64-NEXT: movb $32, -1073741994(%rsp) | ||
; x86_64-NEXT: movb $33, 2147483478(%rsp) | ||
; x86_64-NEXT: movb $34, 1073741654(%rsp) | ||
; x86_64-NEXT: movb $35, -170(%rsp) | ||
; x86_64-NEXT: xorl %eax, %eax | ||
; x86_64-NEXT: movl $4294967176, %ecx # imm = 0xFFFFFF88 | ||
; x86_64-NEXT: addq %rcx, %rsp | ||
; x86_64-NEXT: .cfi_def_cfa_offset 8 | ||
; x86_64-NEXT: retq | ||
entry: | ||
%a = alloca [1073741824 x i8], align 16 | ||
%b = alloca [1073741824 x i8], align 16 | ||
%c = alloca [1073741824 x i8], align 16 | ||
%d = alloca [1073741824 x i8], align 16 | ||
|
||
%arrayida = getelementptr inbounds [1073741824 x i8], ptr %a, i64 0, i64 -42 | ||
%arrayidb = getelementptr inbounds [1073741824 x i8], ptr %b, i64 0, i64 -42 | ||
%arrayidc = getelementptr inbounds [1073741824 x i8], ptr %c, i64 0, i64 -42 | ||
%arrayidd = getelementptr inbounds [1073741824 x i8], ptr %d, i64 0, i64 -42 | ||
|
||
store i8 32, ptr %arrayida, align 2 | ||
store i8 33, ptr %arrayidb, align 2 | ||
store i8 34, ptr %arrayidc, align 2 | ||
store i8 35, ptr %arrayidd, align 2 | ||
|
||
ret i32 0 | ||
} | ||
|
||
define i32 @0() #0 { | ||
; ERR-i686: error: <unknown>:0:0: requesting 64-bit offset in 32-bit immediate | ||
; | ||
; x86_64-LABEL: __unnamed_1: | ||
; x86_64: # %bb.0: # %entry | ||
; x86_64-NEXT: movl $4294967176, %eax # imm = 0xFFFFFF88 | ||
; x86_64-NEXT: subq %rax, %rsp | ||
; x86_64-NEXT: .cfi_def_cfa_offset 4294967184 | ||
; x86_64-NEXT: movb $32, -1073741994(%rsp) | ||
; x86_64-NEXT: movb $33, 2147483478(%rsp) | ||
; x86_64-NEXT: movb $34, 1073741654(%rsp) | ||
; x86_64-NEXT: movb $35, -170(%rsp) | ||
; x86_64-NEXT: xorl %eax, %eax | ||
; x86_64-NEXT: movl $4294967176, %ecx # imm = 0xFFFFFF88 | ||
; x86_64-NEXT: addq %rcx, %rsp | ||
; x86_64-NEXT: .cfi_def_cfa_offset 8 | ||
; x86_64-NEXT: retq | ||
entry: | ||
%a = alloca [1073741824 x i8], align 16 | ||
%b = alloca [1073741824 x i8], align 16 | ||
%c = alloca [1073741824 x i8], align 16 | ||
%d = alloca [1073741824 x i8], align 16 | ||
|
||
%arrayida = getelementptr inbounds [1073741824 x i8], ptr %a, i64 0, i64 -42 | ||
%arrayidb = getelementptr inbounds [1073741824 x i8], ptr %b, i64 0, i64 -42 | ||
%arrayidc = getelementptr inbounds [1073741824 x i8], ptr %c, i64 0, i64 -42 | ||
%arrayidd = getelementptr inbounds [1073741824 x i8], ptr %d, i64 0, i64 -42 | ||
|
||
store i8 32, ptr %arrayida, align 2 | ||
store i8 33, ptr %arrayidb, align 2 | ||
store i8 34, ptr %arrayidc, align 2 | ||
store i8 35, ptr %arrayidd, align 2 | ||
|
||
ret i32 0 | ||
} | ||
|
||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
attributes #0 = { optnone noinline } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This assert was checking to see if Offset addition overflowed on x86-64 - haven't we lost that check now?