Skip to content

Commit 8560da2

Browse files
committed
[PowerPC] Simplify PPCMCExpr::evaluateAsRelocatableImpl
The signedness of the @l result is dependent on the instruction operand (gas behavior). E.g. in `addis 3,3,65535@l`, 65535@l is signed. Unfortunately we don't have the information. bfef1dd (2014) checked `Fixup`, which was unnecessary and mislead https://reviews.llvm.org/D115419 to make the code more complex. In PPCMCExpr::evaluateAsRelocatableImpl we don't need to validate the result. Just continue and rely on the validation in ELFObjectWriter.
1 parent fc6fd6a commit 8560da2

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,17 @@ std::optional<int64_t> PPCMCExpr::evaluateAsInt64(int64_t Value) const {
7373

7474
bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
7575
const MCFixup *Fixup) const {
76+
if (!Asm)
77+
return false;
7678
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
7779
return false;
7880

81+
// The signedness of the result is dependent on the instruction operand. E.g.
82+
// in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
83+
// parse time (!Asm), disable the folding.
7984
std::optional<int64_t> MaybeInt = evaluateAsInt64(Res.getConstant());
8085
if (Res.isAbsolute() && MaybeInt) {
81-
int64_t Result = *MaybeInt;
82-
bool IsHalf16 = Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16;
83-
bool IsHalf16DS =
84-
Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16ds;
85-
bool IsHalf16DQ =
86-
Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16dq;
87-
bool IsHalf = IsHalf16 || IsHalf16DS || IsHalf16DQ;
88-
89-
if (!IsHalf && Result >= 0x8000)
90-
return false;
91-
if ((IsHalf16DS && (Result & 0x3)) || (IsHalf16DQ && (Result & 0xf)))
92-
return false;
93-
94-
Res = MCValue::get(Result);
86+
Res = MCValue::get(*MaybeInt);
9587
} else {
9688
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
9789
getKind());

0 commit comments

Comments
 (0)