-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Fix [PowerPC] llc crashed at -O1/O2/O3: Assertion `isImm() && "Wrong MachineOperand mutator"' failed. #170548
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
diggerlin
wants to merge
3
commits into
llvm:main
Choose a base branch
from
diggerlin:digger/issue-167672
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.
+58
−6
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -797,6 +797,7 @@ bool PPCMIPeephole::simplifyCode() { | |
| case PPC::VSPLTH: | ||
| case PPC::XXSPLTW: { | ||
| unsigned MyOpcode = MI.getOpcode(); | ||
| // The operand number of the source register in the splat instruction. | ||
| unsigned OpNo = MyOpcode == PPC::XXSPLTW ? 1 : 2; | ||
| Register TrueReg = | ||
| TRI->lookThruCopyLike(MI.getOperand(OpNo).getReg(), MRI); | ||
|
|
@@ -823,6 +824,7 @@ bool PPCMIPeephole::simplifyCode() { | |
| (MyOpcode == PPC::XXSPLTW && DefOpcode == PPC::LXVWSX) || | ||
| (MyOpcode == PPC::XXSPLTW && DefOpcode == PPC::MTVSRWS)|| | ||
| (MyOpcode == PPC::XXSPLTW && isConvertOfSplat()); | ||
|
|
||
| // If the instruction[s] that feed this splat have already splat | ||
| // the value, this splat is redundant. | ||
| if (AlreadySplat) { | ||
|
|
@@ -835,30 +837,58 @@ bool PPCMIPeephole::simplifyCode() { | |
| ToErase = &MI; | ||
| Simplified = true; | ||
| } | ||
|
|
||
| // Splat fed by a shift. Usually when we align value to splat into | ||
| // vector element zero. | ||
| if (DefOpcode == PPC::XXSLDWI) { | ||
| Register ShiftRes = DefMI->getOperand(0).getReg(); | ||
| Register ShiftOp1 = DefMI->getOperand(1).getReg(); | ||
| Register ShiftOp2 = DefMI->getOperand(2).getReg(); | ||
| unsigned ShiftImm = DefMI->getOperand(3).getImm(); | ||
| unsigned SplatImm = | ||
| MI.getOperand(MyOpcode == PPC::XXSPLTW ? 2 : 1).getImm(); | ||
|
|
||
| if (ShiftOp1 == ShiftOp2) { | ||
| unsigned NewElem = (SplatImm + ShiftImm) & 0x3; | ||
| // For example, We can erase XXSLDWI from in following: | ||
| // %2:vrrc = XXSLDWI killed %1:vrrc, %1:vrrc, 1 | ||
| // %6:vrrc = VSPLTB 15, killed %2:vrrc | ||
| // %7:vsrc = XXLAND killed %6:vrrc, killed %1:vrrc | ||
| // | ||
| // ---> | ||
| // | ||
| // %6:vrrc = VSPLTB 3, killed %1:vrrc | ||
| // %7:vsrc = XXLAND killed %6:vrrc, killed %1:vrrc | ||
|
|
||
| Register ShiftRes = DefMI->getOperand(0).getReg(); | ||
|
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. can just inline to the call since only have 1 use. |
||
| if (MRI->hasOneNonDBGUse(ShiftRes)) { | ||
| LLVM_DEBUG(dbgs() << "Removing redundant shift: "); | ||
| LLVM_DEBUG(DefMI->dump()); | ||
| ToErase = DefMI; | ||
| } | ||
| Simplified = true; | ||
| unsigned ShiftImm = DefMI->getOperand(3).getImm(); | ||
| // The operand number of the splat Imm in the instruction. | ||
| unsigned SplatImmNo = MyOpcode == PPC::XXSPLTW ? 2 : 1; | ||
| unsigned SplatImm = MI.getOperand(SplatImmNo).getImm(); | ||
|
|
||
| // Calculate the new splat-element immediate. We need to convert the | ||
| // element index into the proper unit (byte for VSPLTB, halfword for | ||
| // VSPLTH, word for VSPLTW) because PPC::XXSLDWI interprets its | ||
| // ShiftImm in 32-bit word units. | ||
| auto CalculateNewElementIdx = [&](unsigned Opcode) { | ||
| if (Opcode == PPC::VSPLTB) | ||
| return (SplatImm + ShiftImm * 4) & 0xF; | ||
| else if (Opcode == PPC::VSPLTH) | ||
| return (SplatImm + ShiftImm * 2) & 0x7; | ||
| else | ||
| return (SplatImm + ShiftImm) & 0x3; | ||
| }; | ||
|
|
||
| unsigned NewElem = CalculateNewElementIdx(MyOpcode); | ||
|
|
||
| LLVM_DEBUG(dbgs() << "Changing splat immediate from " << SplatImm | ||
| << " to " << NewElem << " in instruction: "); | ||
| LLVM_DEBUG(MI.dump()); | ||
| addRegToUpdate(MI.getOperand(OpNo).getReg()); | ||
| addRegToUpdate(ShiftOp1); | ||
| MI.getOperand(OpNo).setReg(ShiftOp1); | ||
| MI.getOperand(2).setImm(NewElem); | ||
| MI.getOperand(SplatImmNo).setImm(NewElem); | ||
| } | ||
| } | ||
| break; | ||
|
|
||
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,22 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: llc -verify-machineinstrs -mcpu=pwr7 -ppc-asm-full-reg-names -mtriple=powerpc64-ibm-aix < %s | \ | ||
| ; RUN: FileCheck %s | ||
|
|
||
|
|
||
| define <4 x i8> @backsmith_pure_1(<8 x i32> %0) { | ||
| ; CHECK-LABEL: backsmith_pure_1: | ||
| ; CHECK: # %bb.0: # %entry | ||
| ; CHECK-NEXT: ld r3, L..C0(r2) # %const.0 | ||
| ; CHECK-NEXT: xxsldwi vs34, vs35, vs35, 1 | ||
| ; CHECK-NEXT: lxvw4x vs36, 0, r3 | ||
| ; CHECK-NEXT: vspltb v3, v3, 3 | ||
| ; CHECK-NEXT: vperm v2, v2, v2, v4 | ||
| ; CHECK-NEXT: xxland vs34, vs35, vs34 | ||
| ; CHECK-NEXT: blr | ||
| entry: | ||
| %shuffle = shufflevector <8 x i32> %0, <8 x i32> zeroinitializer, <4 x i32> <i32 5, i32 6, i32 7, i32 4> | ||
| %conv4 = trunc <4 x i32> %shuffle to <4 x i8> | ||
| %shift = shufflevector <4 x i8> %conv4, <4 x i8> zeroinitializer, <4 x i32> <i32 3, i32 poison, i32 poison, i32 poison> | ||
| %foldExtExtBinop = and <4 x i8> %shift, %conv4 | ||
| ret <4 x i8> %foldExtExtBinop | ||
| } |
Oops, something went wrong.
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.
can just inline to the call since only have 1 use.