[llvm] [Float2Int] Fix miscompile with floats that can be converted to large values (PR #85996)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 15:05:57 PDT 2024


================
@@ -349,3 +349,55 @@ bogusBB:                                          ; preds = %bogusBB
   %tobool = fcmp une double %inc, 0.000000e+00
   br label %bogusBB
 }
+
+define i32 @pr79158() {
+; CHECK-LABEL: @pr79158(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[X_I:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[X_I]])
+; CHECK-NEXT:    store volatile i32 1, ptr [[X_I]], align 4
+; CHECK-NEXT:    [[X_I_0_X_I_0_X_0_X_0_X_0__I:%.*]] = load volatile i32, ptr [[X_I]], align 4
+; CHECK-NEXT:    [[CMP_I:%.*]] = icmp sgt i32 [[X_I_0_X_I_0_X_0_X_0_X_0__I]], 0
+; CHECK-NEXT:    [[TMP0:%.*]] = zext i1 [[CMP_I]] to i32
+; CHECK-NEXT:    [[MUL_I1:%.*]] = mul i32 [[TMP0]], -1
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[X_I]])
+; CHECK-NEXT:    ret i32 0
+;
+entry:
+  %x.i = alloca i32, align 4
+  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %x.i)
+  store volatile i32 1, ptr %x.i, align 4
+  %x.i.0.x.i.0.x.0.x.0.x.0..i = load volatile i32, ptr %x.i, align 4
+  %cmp.i = icmp sgt i32 %x.i.0.x.i.0.x.0.x.0.x.0..i, 0
+  %conv.i = uitofp i1 %cmp.i to double
----------------
AtariDreams wrote:

> The range in the debug print for this instruction seems problematic
> 
> ```
> F2I:   %conv.i = uitofp i1 %cmp.i to double:[0,1)
> ```
> 
> That range only contains one value, 0.
> 
> The pass computed a minimum bitwidth of 3
> 
> ```
> F2I: MinBitwidth=3, R: [0,1)
> ```

That means either R.getLower().getSignificantBits() or R.getHigher().getSignificantBits() returned 2.

Because that + 1 makes 3

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


More information about the llvm-commits mailing list