From 269ffdac4e354b58cb627a45a9ffe01fb967004a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 6 Dec 2016 23:18:06 +0000 Subject: [PATCH] AMDGPU: Fix crash on i16 constant expression llvm-svn: 288861 --- llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp | 5 ++-- .../AMDGPU/amdgpu-codegenprepare-i16-to-i32.ll | 28 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp index b427de1..2e8db08 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp @@ -146,9 +146,10 @@ public: Value *AMDGPUCodeGenPrepare::copyFlags( const BinaryOperator &I, Value *V) const { - assert(isa(V) && "V must be binary operation"); + BinaryOperator *BinOp = dyn_cast(V); + if (!BinOp) // Possibly constant expression. + return V; - BinaryOperator *BinOp = cast(V); if (isa(BinOp)) { BinOp->setHasNoSignedWrap(I.hasNoSignedWrap()); BinOp->setHasNoUnsignedWrap(I.hasNoUnsignedWrap()); diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-i16-to-i32.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-i16-to-i32.ll index 5444b74a..13e4192 100644 --- a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-i16-to-i32.ll +++ b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-i16-to-i32.ll @@ -533,6 +533,27 @@ define i16 @add_i16(i16 %a, i16 %b) { ret i16 %r } +; GCN-LABEL: @constant_add_i16( +; VI: ret i16 3 +define i16 @constant_add_i16() { + %r = add i16 1, 2 + ret i16 %r +} + +; GCN-LABEL: @constant_add_nsw_i16( +; VI: ret i16 3 +define i16 @constant_add_nsw_i16() { + %r = add nsw i16 1, 2 + ret i16 %r +} + +; GCN-LABEL: @constant_add_nuw_i16( +; VI: ret i16 3 +define i16 @constant_add_nuw_i16() { + %r = add nsw i16 1, 2 + ret i16 %r +} + ; GCN-LABEL: @add_nsw_i16( ; SI: %r = add nsw i16 %a, %b ; SI-NEXT: ret i16 %r @@ -806,6 +827,13 @@ define i16 @ashr_exact_i16(i16 %a, i16 %b) { ret i16 %r } +; GCN-LABEL: @constant_lshr_exact_i16( +; VI: ret i16 2 +define i16 @constant_lshr_exact_i16(i16 %a, i16 %b) { + %r = lshr exact i16 4, 1 + ret i16 %r +} + ; GCN-LABEL: @and_i16( ; SI: %r = and i16 %a, %b ; SI-NEXT: ret i16 %r -- 2.7.4