diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-06-21 00:35:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-21 00:35:17 +0200 |
commit | 6015749720ca2f5572b742185e9d236bf5a2b835 (patch) | |
tree | 23d65b628377457a59a280c62aa59f2d90c162c4 /compiler | |
parent | 1be82d96a682338ba53832bcc2772b7865b47b57 (diff) | |
parent | fb62dd1fae7a405d80f0d4257ddb1f4d48e204f0 (diff) | |
download | Nim-6015749720ca2f5572b742185e9d236bf5a2b835.tar.gz |
Merge pull request #8062 from LemonBoy/fix-7825
Fix constant folding for shl/not
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semfold.nim | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 10a223ea2..eceb10470 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -211,7 +211,12 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode = of mUnaryMinusF64: result = newFloatNodeT(- getFloat(a), n, g) of mNot: result = newIntNodeT(1 - getInt(a), n, g) of mCard: result = newIntNodeT(nimsets.cardSet(g.config, a), n, g) - of mBitnotI: result = newIntNodeT(not getInt(a), n, g) + of mBitnotI: + case skipTypes(n.typ, abstractRange).kind + of tyUInt..tyUInt64: + result = newIntNodeT((not getInt(a)) and lastOrd(g.config, a.typ, fixedUnsigned=true), n, g) + else: + result = newIntNodeT(not getInt(a), n, g) of mLengthArray: result = newIntNodeT(lengthOrd(g.config, a.typ), n, g) of mLengthSeq, mLengthOpenArray, mXLenSeq, mLengthStr, mXLenStr: if a.kind == nkNilLit: @@ -250,8 +255,10 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode = of tyInt8: result = newIntNodeT(int8(getInt(a)) shl int8(getInt(b)), n, g) of tyInt16: result = newIntNodeT(int16(getInt(a)) shl int16(getInt(b)), n, g) of tyInt32: result = newIntNodeT(int32(getInt(a)) shl int32(getInt(b)), n, g) - of tyInt64, tyInt, tyUInt..tyUInt64: + of tyInt64, tyInt: result = newIntNodeT(`shl`(getInt(a), getInt(b)), n, g) + of tyUInt..tyUInt64: + result = newIntNodeT(`shl`(getInt(a), getInt(b)) and lastOrd(g.config, a.typ, fixedUnsigned=true), n, g) else: internalError(g.config, n.info, "constant folding for shl") of mShrI: case skipTypes(n.typ, abstractRange).kind |