diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp index 0c6700075..3ea202e7a 100644 --- a/lib/HLSL/HLOperationLower.cpp +++ b/lib/HLSL/HLOperationLower.cpp @@ -1981,7 +1981,7 @@ Value *TranslateFrexp(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode, // bool ne = val != 0; Value *notZero = Builder.CreateFCmpUNE(val, zeroVal); - notZero = Builder.CreateZExt(notZero, dstTy); + notZero = Builder.CreateSExt(notZero, dstTy); Value *intVal = Builder.CreateBitCast(val, dstTy); // temp = intVal & exponentMask; diff --git a/tools/clang/test/CodeGenHLSL/batch/expressions/intrinsics/frexp.hlsl b/tools/clang/test/CodeGenHLSL/batch/expressions/intrinsics/frexp.hlsl new file mode 100644 index 000000000..fe66ecfa2 --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/batch/expressions/intrinsics/frexp.hlsl @@ -0,0 +1,18 @@ +// RUN: %dxc -E main -T ps_6_2 %s | FileCheck %s + +// Make sure frexp generate code pattern. +// CHECK:bitcast float {{.*}} to i32 +// CHECK:and i32 {{.*}}, 2139095040 +// CHECK:add {{.*}}, -1056964608 +// CHECK:ashr {{.*}}, 23 +// CHECK:sitofp +// CHECK:and i32 {{.*}}, 8388607 +// CHECK:or i32 {{.*}}, 1056964608 +// CHECK:fadd + +float main(float a:A) : SV_Target { + float b; + float c = frexp ( a , b ); + + return b+c; +} \ No newline at end of file