[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 10:57:27 PDT 2024


alexfh wrote:

Apologies for resurrecting this old thread, but I found a problem with this patch. It seems like it makes a comparator violate strict weak ordering requirements. This manifests as an assertion failure when Clang is compiled with the corresponding libc++ check:
```
clang -O1 -c -o /dev/null -x ir -
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: cold noreturn nounwind
declare void @llvm.ubsantrap(i8 immarg) #0

define void @f(ptr %cpi, ptr %x, i32 %i.0, i1 %cmp125.not) {
entry:
  br label %for.cond

trap3:                                            ; preds = %if.end147, %if.else141, %for.body
  call void @llvm.ubsantrap(i8 0)
  unreachable

for.cond:                                         ; preds = %cont93, %entry
  %i.01 = phi i32 [ 0, %entry ], [ %inc, %cont93 ]
  %cmp91 = icmp ult i32 %i.01, 20
  br i1 %cmp91, label %for.body, label %for.cond116

for.body:                                         ; preds = %for.cond
  %0 = icmp eq ptr %x, null
  br i1 %0, label %cont93, label %trap3

cont93:                                           ; preds = %for.body
  %inc = or i32 %i.0, 1
  br label %for.cond

for.cond116:                                      ; preds = %cont148, %for.cond
  %i.1 = phi i32 [ %inc158, %cont148 ], [ 0, %for.cond ]
  %cmp117 = icmp ult i32 %i.1, 20
  br i1 %cmp117, label %cont120, label %cont213

cont120:                                          ; preds = %for.cond116
  br i1 %cmp125.not, label %if.else141, label %if.end147

if.else141:                                       ; preds = %cont120
  %1 = ptrtoint ptr %x to i64
  %2 = and i64 %1, 1
  %3 = icmp eq i64 %2, 0
  br i1 %3, label %cont146, label %trap3

cont146:                                          ; preds = %if.else141
  store i32 0, ptr %cpi, align 4
  br label %if.end147

if.end147:                                        ; preds = %cont146, %cont120
  %4 = ptrtoint ptr %x to i64
  %5 = and i64 %4, 1
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %cont148, label %trap3

cont148:                                          ; preds = %if.end147
  %inc158 = or i32 %i.0, 1
  br label %for.cond116

cont213:                                          ; preds = %for.cond116
  ret void
}

attributes #0 = { cold noreturn nounwind }
include/c++/v1/__debug_utils/strict_weak_ordering_check.h:59: assertion __comp(*(__first + __a), *(__first + __b)) failed: Your comparator is not a valid strict-weak ordering
PLEASE submit a bug report to ... and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: blaze-bin/third_party/llvm/llvm-project/clang/clang -O1 -c -o /dev/null -x ir -
1.      Optimizer
```



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


More information about the cfe-commits mailing list