[PATCH] D89390: [TargetLowering] Update optimization to check for boolean content

Erik Hogeman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 10:41:44 PDT 2020


ErikHogeman updated this revision to Diff 299415.
ErikHogeman added a comment.

Adds the patch as a diff on top of the test, so that the new code diff becomes more visible.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89390/new/

https://reviews.llvm.org/D89390

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/test/CodeGen/NVPTX/pow2_mask_cmp.ll


Index: llvm/test/CodeGen/NVPTX/pow2_mask_cmp.ll
===================================================================
--- llvm/test/CodeGen/NVPTX/pow2_mask_cmp.ll
+++ llvm/test/CodeGen/NVPTX/pow2_mask_cmp.ll
@@ -2,9 +2,15 @@
 
 ; Tests the following pattern:
 ; (X & 8) != 0 --> (X & 8) >> 3
+;
+; This produces incorrect code when boolean false is represented
+; as a negative one, and this test checks that the transform is
+; not triggered.
 
 ; CHECK-LABEL: @pow2_mask_cmp
-; CHECK: bfe.u32 {{%r[0-9]+}}, {{%r[0-9]+}}, 3, 1
+; CHECK: and.b32 [[AND:%r[0-9]+]], %r{{[0-9]+}}, 8
+; CHECK: setp.ne.s32 [[SETP:%p[0-9+]]], [[AND]], 0
+; CHECK: selp.u32 %r{{[0-9]+}}, 1, 0, [[SETP]]
 define i32 @pow2_mask_cmp(i32 %x) {
   %a = and i32 %x, 8
   %cmp = icmp ne i32 %a, 0
Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -3981,7 +3981,8 @@
     EVT ShValTy = N0.getValueType();
 
     // Fold bit comparisons when we can.
-    if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
+    if (getBooleanContents(N0.getValueType()) == ZeroOrOneBooleanContent &&
+        (Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
         (VT == ShValTy || (isTypeLegal(VT) && VT.bitsLE(ShValTy))) &&
         N0.getOpcode() == ISD::AND) {
       if (auto *AndRHS = dyn_cast<ConstantSDNode>(N0.getOperand(1))) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89390.299415.patch
Type: text/x-patch
Size: 1468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201020/d1bedddd/attachment.bin>


More information about the llvm-commits mailing list