From c40dab20691fd33f49715104ea7182d3ce14d2b2 Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Thu, 16 Oct 2014 16:41:15 +0000 Subject: [PATCH] [AArch64] Fix miscompile of sdiv-by-power-of-2. When the constant divisor was larger than 32bits, then the optimized code generated for the AArch64 backend would emit the wrong code, because the shift was defined as a shift of a 32bit constant '(1<getOperand(0); unsigned Lg2 = Divisor.countTrailingZeros(); SDValue Zero = DAG.getConstant(0, VT); - SDValue Pow2MinusOne = DAG.getConstant((1 << Lg2) - 1, VT); + SDValue Pow2MinusOne = DAG.getConstant((1ULL << Lg2) - 1, VT); // Add (N0 < 0) ? Pow2 - 1 : 0; SDValue CCVal; diff --git a/test/CodeGen/AArch64/sdivpow2.ll b/test/CodeGen/AArch64/sdivpow2.ll index 6dee06dbd65..6c02ea9a467 100644 --- a/test/CodeGen/AArch64/sdivpow2.ll +++ b/test/CodeGen/AArch64/sdivpow2.ll @@ -1,4 +1,5 @@ -; RUN: llc -mtriple=arm64-linux-gnu -o - %s | FileCheck %s +; RUN: llc -mtriple=arm64-linux-gnu -fast-isel=0 -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=arm64-linux-gnu -fast-isel=1 -verify-machineinstrs < %s | FileCheck %s define i32 @test1(i32 %x) { ; CHECK-LABEL: test1 @@ -59,3 +60,15 @@ define i64 @test6(i64 %x) { %div = sdiv i64 %x, 64 ret i64 %div } + +define i64 @test7(i64 %x) { +; CHECK-LABEL: test7 +; CHECK: orr [[REG:x[0-9]+]], xzr, #0xffffffffffff +; CHECK: add x8, x0, [[REG]] +; CHECK: cmp x0, #0 +; CHECK: csel x8, x8, x0, lt +; CHECK: asr x0, x8, #48 + %div = sdiv i64 %x, 281474976710656 + ret i64 %div +} +