summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/nativeGen/X86/Ppr.hs6
-rw-r--r--testsuite/tests/codeGen/should_run/T13425.hs10
-rw-r--r--testsuite/tests/codeGen/should_run/T13425.stdout1
-rw-r--r--testsuite/tests/codeGen/should_run/all.T1
4 files changed, 17 insertions, 1 deletions
diff --git a/compiler/nativeGen/X86/Ppr.hs b/compiler/nativeGen/X86/Ppr.hs
index 7d19e990ce..5044c83c89 100644
--- a/compiler/nativeGen/X86/Ppr.hs
+++ b/compiler/nativeGen/X86/Ppr.hs
@@ -671,8 +671,12 @@ pprInstr (TEST format src dst) = sdocWithPlatform $ \platform ->
-- (We could handle masks larger than a single byte too,
-- but it would complicate the code considerably
-- and tag checks are by far the most common case.)
+ -- The mask must have the high bit clear for this smaller encoding
+ -- to be completely equivalent to the original; in particular so
+ -- that the signed comparison condition bits are the same as they
+ -- would be if doing a full word comparison. See Trac #13425.
(OpImm (ImmInteger mask), OpReg dstReg)
- | 0 <= mask && mask < 256 -> minSizeOfReg platform dstReg
+ | 0 <= mask && mask < 128 -> minSizeOfReg platform dstReg
_ -> format
in pprFormatOpOp (sLit "test") format' src dst
where
diff --git a/testsuite/tests/codeGen/should_run/T13425.hs b/testsuite/tests/codeGen/should_run/T13425.hs
new file mode 100644
index 0000000000..49d07211cc
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/T13425.hs
@@ -0,0 +1,10 @@
+import Data.Bits ((.&.))
+
+flags :: Int -> Int
+flags x
+ | x .&. 128 > 0 = 12
+ | otherwise = 13
+{-# NOINLINE flags #-}
+
+main :: IO ()
+main = print (flags 255)
diff --git a/testsuite/tests/codeGen/should_run/T13425.stdout b/testsuite/tests/codeGen/should_run/T13425.stdout
new file mode 100644
index 0000000000..48082f72f0
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/T13425.stdout
@@ -0,0 +1 @@
+12
diff --git a/testsuite/tests/codeGen/should_run/all.T b/testsuite/tests/codeGen/should_run/all.T
index b952c10dc4..ffe4b64cbe 100644
--- a/testsuite/tests/codeGen/should_run/all.T
+++ b/testsuite/tests/codeGen/should_run/all.T
@@ -155,3 +155,4 @@ test('T9577', [ unless(arch('x86_64') or arch('i386'),skip),
when(opsys('darwin'), expect_broken(12937)),
when(opsys('mingw32'), expect_broken(12965)),
only_ways(['normal']) ], compile_and_run, [''])
+test('T13425', normal, compile_and_run, ['-O'])