[llvm] [X86][CodeGen] Support lowering for CCMP/CTEST (PR #91747)

Shengchen Kan via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 09:05:42 PDT 2024


================
@@ -1764,11 +1764,8 @@ void DAGCombiner::Run(CombineLevel AtLevel) {
 
     if (N->getNumValues() == RV->getNumValues())
       DAG.ReplaceAllUsesWith(N, RV.getNode());
-    else {
-      assert(N->getValueType(0) == RV.getValueType() &&
-             N->getNumValues() == 1 && "Type mismatch");
----------------
KanRobert wrote:

Ah, I reproduced it finally.

```
define i8 @ccmp_tmp(i8 %a, i8 %b, i8* nocapture %c)  {
entry:
  %tobool = icmp ne i8 %a, 0
  %cmp = icmp sgt i8 %b, 1
  %or.cond = select i1 %tobool, i1 %cmp, i1 false
  br i1 %or.cond, label %if.then, label %if.end

if.then:
  store i8 %a, i8* %c, align 4
  br label %if.end

if.end:
  ret i8 0
}
```

```
SelectionDAG has 24 nodes:
  t0: ch,glue = EntryToken
    t2: i32,ch = CopyFromReg t0, Register:i32 %0
  t3: i8 = truncate t2
      t10: ch = CopyToReg t0, Register:i8 %3, t3
            t42: i32 = X86ISD::CMP t3, Constant:i8<0>
          t43: i8 = X86ISD::SETCC TargetConstant:i8<5>, t42
                t5: i32,ch = CopyFromReg t0, Register:i32 %1
              t6: i8 = truncate t5
            t39: i8,i32 = X86ISD::SUB t6, Constant:i8<2>
          t41: i8 = X86ISD::SETCC TargetConstant:i8<13>, t39:1
        t30: i8 = and t43, t41
      t35: i8,i32 = X86ISD::SUB t30, Constant:i8<1>
    t37: ch = X86ISD::BRCOND t10, BasicBlock:ch<if.end 0x82352c0>, TargetConstant:i8<5>, t35:1
  t24: ch = br t37, BasicBlock:ch<if.then 0x82351c0>
```

I will add it to the ccmp.ll to improve the test coverage.

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


More information about the llvm-commits mailing list