[llvm] [ValueTracking] Fix incorrect inferrence about the signbit of sqrt (PR #92510)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 01:11:15 PDT 2024


================
@@ -1698,6 +1698,21 @@ define i32 @test_none(float nofpclass(all) %x) {
   ret i32 %and
 }
 
+; We cannot make assumptions about the sign of result of sqrt
+; when the input is a negative value (except for -0).
+define i1 @pr92217() {
+; CHECK-LABEL: @pr92217(
+; CHECK-NEXT:    [[X:%.*]] = call float @llvm.sqrt.f32(float 0xC6DEBE9E60000000)
+; CHECK-NEXT:    [[Y:%.*]] = bitcast float [[X]] to i32
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[Y]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %x = call float @llvm.sqrt.f32(float 0xC6DEBE9E60000000)
+  %y = bitcast float %x to i32
+  %cmp = icmp slt i32 %y, 0
+  ret i1 %cmp
+}
+
----------------
arsenm wrote:

Also test with nnan case, and non-constant source 

https://github.com/llvm/llvm-project/pull/92510


More information about the llvm-commits mailing list