Skip to content

Commit 3952f98

Browse files
author
Thorsten Schütt
committed
address review comments
1 parent 810973e commit 3952f98

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelperCasts.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,31 @@ bool CombinerHelper::matchTruncateOfExt(const MachineInstr &Root,
133133
MatchInfo = [=](MachineIRBuilder &B) { B.buildCopy(Dst, Src); };
134134

135135
return true;
136-
} else if (SrcTy.getScalarSizeInBits() < DstTy.getScalarSizeInBits()) {
137-
// Protect against scalable vectors.
136+
}
137+
138+
if (SrcTy.getScalarSizeInBits() < DstTy.getScalarSizeInBits()) {
139+
// If the source is smaller than the destination, we need to extend.
140+
138141
if (!isLegalOrBeforeLegalizer({Ext->getOpcode(), {DstTy, SrcTy}}))
139142
return false;
140143

141-
// If the source is smaller than the destination, we need to extend.
142144
MatchInfo = [=](MachineIRBuilder &B) {
143145
B.buildInstr(Ext->getOpcode(), {Dst}, {Src});
144146
};
145147

146148
return true;
147149
}
148150

149-
// The source is larger than the destination. We need to truncate.
151+
if (SrcTy.getScalarSizeInBits() > DstTy.getScalarSizeInBits()) {
152+
// The source is larger than the destination. We need to truncate.
150153

151-
if (!isLegalOrBeforeLegalizer({TargetOpcode::G_TRUNC, {DstTy, SrcTy}}))
152-
return false;
154+
if (!isLegalOrBeforeLegalizer({TargetOpcode::G_TRUNC, {DstTy, SrcTy}}))
155+
return false;
153156

154-
MatchInfo = [=](MachineIRBuilder &B) { B.buildTrunc(Dst, Src); };
157+
MatchInfo = [=](MachineIRBuilder &B) { B.buildTrunc(Dst, Src); };
155158

156-
return true;
159+
return true;
160+
}
161+
162+
return false;
157163
}

0 commit comments

Comments
 (0)