;;         (-524288..524287) for long displacement
 ;;    M -- Constant integer with a value of 0x7fffffff.
 ;;    N -- Multiple letter constraint followed by 4 parameter letters.
-;;         0..9:  number of the part counting from most to least significant
-;;         H,Q:   mode of the part
-;;         D,S,H: mode of the containing operand
-;;         0,F:   value of the other parts (F - all bits set)
+;;         0..9,x:  number of the part counting from most to least significant
+;;         H,Q:     mode of the part
+;;         D,S,H:   mode of the containing operand
+;;         0,F:     value of the other parts (F - all bits set)
 ;;
 ;;         The constraint matches if the specified part of a constant
-;;         has a value different from its other parts.
+;;         has a value different from its other parts.  If the letter x
+;;         is specified instead of a part number, the constraint matches
+;;         if there is any single part with non-default value.
 ;;    Q -- Memory reference without index register and with short displacement.
 ;;    R -- Memory reference with index register and short displacement.
 ;;    S -- Memory reference without index register but with long displacement.
 ;;    T -- Memory reference with index register and long displacement.
+;;    A -- Multiple letter constraint followed by Q, R, S, or T:
+;;         Offsettable memory reference of type specified by second letter.
 ;;    U -- Pointer with short displacement.
 ;;    W -- Pointer with long displacement.
 ;;    Y -- Shift count operand.
   [(set_attr "op_type"  "RRE,RXY")])
 
 (define_insn "*anddi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,d,Q")
+  [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,d,AQ,Q")
         (and:DI (match_operand:DI 1 "nonimmediate_operand"
-                                    "%d,o,0,0,0,0,0,0,0")
+                                    "%d,o,0,0,0,0,0,0,0,0")
                 (match_operand:DI 2 "general_operand"
-                                    "M,M,N0HDF,N1HDF,N2HDF,N3HDF,d,m,Q")))
+                                    "M,M,N0HDF,N1HDF,N2HDF,N3HDF,d,m,NxQDF,Q")))
    (clobber (reg:CC 33))]
   "TARGET_64BIT && s390_logical_operator_ok_p (operands)"
   "@
    nill\t%0,%j2
    ngr\t%0,%2
    ng\t%0,%2
+   #
    nc\t%O0(8,%R0),%2"
-  [(set_attr "op_type" "RRE,RXE,RI,RI,RI,RI,RRE,RXY,SS")])
+  [(set_attr "op_type" "RRE,RXE,RI,RI,RI,RI,RRE,RXY,SI,SS")])
+
+(define_split
+  [(set (match_operand:DI 0 "s_operand" "")
+        (and:DI (match_dup 0) (match_operand:DI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (AND, &operands[0], &operands[1]);")
 
 (define_expand "anddi3"
   [(set (match_operand:DI 0 "nonimmediate_operand" "")
   [(set_attr "op_type"  "RR,RX,RXY")])
 
 (define_insn "*andsi3_zarch"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,Q")
-        (and:SI (match_operand:SI 1 "nonimmediate_operand" "%d,o,0,0,0,0,0,0")
-                (match_operand:SI 2 "general_operand" "M,M,N0HSF,N1HSF,d,R,T,Q")))
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,d,d,d,AQ,Q")
+        (and:SI (match_operand:SI 1 "nonimmediate_operand"
+                                    "%d,o,0,0,0,0,0,0,0")
+                (match_operand:SI 2 "general_operand"
+                                    "M,M,N0HSF,N1HSF,d,R,T,NxQSF,Q")))
    (clobber (reg:CC 33))]
   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    nr\t%0,%2
    n\t%0,%2
    ny\t%0,%2
+   #
    nc\t%O0(4,%R0),%2"
-  [(set_attr "op_type"  "RRE,RXE,RI,RI,RR,RX,RXY,SS")])
+  [(set_attr "op_type"  "RRE,RXE,RI,RI,RR,RX,RXY,SI,SS")])
 
 (define_insn "*andsi3_esa"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,Q")
-        (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0")
-                (match_operand:SI 2 "general_operand" "d,R,Q")))
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,AQ,Q")
+        (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
+                (match_operand:SI 2 "general_operand" "d,R,NxQSF,Q")))
    (clobber (reg:CC 33))]
   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    nr\t%0,%2
    n\t%0,%2
+   #
    nc\t%O0(4,%R0),%2"
-  [(set_attr "op_type"  "RR,RX,SS")])
+  [(set_attr "op_type"  "RR,RX,SI,SS")])
+
+(define_split
+  [(set (match_operand:SI 0 "s_operand" "")
+        (and:SI (match_dup 0) (match_operand:SI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (AND, &operands[0], &operands[1]);")
 
 (define_expand "andsi3"
   [(set (match_operand:SI 0 "nonimmediate_operand" "")
 ;
 
 (define_insn "*andhi3_zarch"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,Q")
-        (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
-                (match_operand:HI 2 "general_operand" "d,n,Q")))
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,AQ,Q")
+        (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0,0")
+                (match_operand:HI 2 "general_operand" "d,n,NxQHF,Q")))
    (clobber (reg:CC 33))]
   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    nr\t%0,%2
    nill\t%0,%x2
+   #
    nc\t%O0(2,%R0),%2"
-  [(set_attr "op_type"  "RR,RI,SS")])
+  [(set_attr "op_type"  "RR,RI,SI,SS")])
 
 (define_insn "*andhi3_esa"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,Q")
-        (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
-                (match_operand:HI 2 "general_operand" "d,Q")))
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,AQ,Q")
+        (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
+                (match_operand:HI 2 "general_operand" "d,NxQHF,Q")))
    (clobber (reg:CC 33))]
   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    nr\t%0,%2
+   #
    nc\t%O0(2,%R0),%2"
-  [(set_attr "op_type"  "RR,SS")])
+  [(set_attr "op_type"  "RR,SI,SS")])
+
+(define_split
+  [(set (match_operand:HI 0 "s_operand" "")
+        (and:HI (match_dup 0) (match_operand:HI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (AND, &operands[0], &operands[1]);")
 
 (define_expand "andhi3"
   [(set (match_operand:HI 0 "nonimmediate_operand" "")
   [(set_attr "op_type"  "RRE,RXY")])
 
 (define_insn "*iordi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,d,d,Q")
-        (ior:DI (match_operand:DI 1 "nonimmediate_operand" "0,0,0,0,0,0,0")
+  [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,d,d,d,AQ,Q")
+        (ior:DI (match_operand:DI 1 "nonimmediate_operand" "0,0,0,0,0,0,0,0")
                 (match_operand:DI 2 "general_operand"
-                                    "N0HD0,N1HD0,N2HD0,N3HD0,d,m,Q")))
+                                    "N0HD0,N1HD0,N2HD0,N3HD0,d,m,NxQD0,Q")))
    (clobber (reg:CC 33))]
   "TARGET_64BIT && s390_logical_operator_ok_p (operands)"
   "@
    oill\t%0,%i2
    ogr\t%0,%2
    og\t%0,%2
+   #
    oc\t%O0(8,%R0),%2"
-  [(set_attr "op_type"  "RI,RI,RI,RI,RRE,RXY,SS")])
+  [(set_attr "op_type"  "RI,RI,RI,RI,RRE,RXY,SI,SS")])
+
+(define_split
+  [(set (match_operand:DI 0 "s_operand" "")
+        (ior:DI (match_dup 0) (match_operand:DI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (ior:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (IOR, &operands[0], &operands[1]);")
 
 (define_expand "iordi3"
   [(set (match_operand:DI 0 "nonimmediate_operand" "")
   [(set_attr "op_type"  "RR,RX,RXY")])
 
 (define_insn "*iorsi3_zarch"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,d,Q")
-        (ior:SI (match_operand:SI 1 "nonimmediate_operand" "0,0,0,0,0,0")
-                (match_operand:SI 2 "general_operand" "N0HS0,N1HS0,d,R,T,Q")))
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,d,d,AQ,Q")
+        (ior:SI (match_operand:SI 1 "nonimmediate_operand" "0,0,0,0,0,0,0")
+                (match_operand:SI 2 "general_operand" "N0HS0,N1HS0,d,R,T,NxQS0,Q")))
    (clobber (reg:CC 33))]
   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    or\t%0,%2
    o\t%0,%2
    oy\t%0,%2
+   #
    oc\t%O0(4,%R0),%2"
-  [(set_attr "op_type"  "RI,RI,RR,RX,RXY,SS")])
+  [(set_attr "op_type"  "RI,RI,RR,RX,RXY,SI,SS")])
 
 (define_insn "*iorsi3_esa"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,Q")
-        (ior:SI (match_operand:SI 1 "nonimmediate_operand" "0,0,0")
-                (match_operand:SI 2 "general_operand" "d,R,Q")))
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,AQ,Q")
+        (ior:SI (match_operand:SI 1 "nonimmediate_operand" "0,0,0,0")
+                (match_operand:SI 2 "general_operand" "d,R,NxQS0,Q")))
    (clobber (reg:CC 33))]
   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    or\t%0,%2
    o\t%0,%2
+   #
    oc\t%O0(4,%R0),%2"
-  [(set_attr "op_type"  "RR,RX,SS")])
+  [(set_attr "op_type"  "RR,RX,SI,SS")])
+
+(define_split
+  [(set (match_operand:SI 0 "s_operand" "")
+        (ior:SI (match_dup 0) (match_operand:SI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (ior:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (IOR, &operands[0], &operands[1]);")
 
 (define_expand "iorsi3"
   [(set (match_operand:SI 0 "nonimmediate_operand" "")
 ;
 
 (define_insn "*iorhi3_zarch"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,Q")
-        (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
-                (match_operand:HI 2 "general_operand" "d,n,Q")))
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,AQ,Q")
+        (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0,0")
+                (match_operand:HI 2 "general_operand" "d,n,NxQH0,Q")))
    (clobber (reg:CC 33))]
   "TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    or\t%0,%2
    oill\t%0,%x2
+   #
    oc\t%O0(2,%R0),%2"
-  [(set_attr "op_type"  "RR,RI,SS")])
+  [(set_attr "op_type"  "RR,RI,SI,SS")])
 
 (define_insn "*iorhi3_esa"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,Q")
-        (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
-                (match_operand:HI 2 "general_operand" "d,Q")))
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,AQ,Q")
+        (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
+                (match_operand:HI 2 "general_operand" "d,NxQH0,Q")))
    (clobber (reg:CC 33))]
   "!TARGET_ZARCH && s390_logical_operator_ok_p (operands)"
   "@
    or\t%0,%2
+   #
    oc\t%O0(2,%R0),%2"
-  [(set_attr "op_type"  "RR,SS")])
+  [(set_attr "op_type"  "RR,SI,SS")])
+
+(define_split
+  [(set (match_operand:HI 0 "s_operand" "")
+        (ior:HI (match_dup 0) (match_operand:HI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (ior:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (IOR, &operands[0], &operands[1]);")
 
 (define_expand "iorhi3"
   [(set (match_operand:HI 0 "nonimmediate_operand" "")
   [(set_attr "op_type"  "RRE,RXY")])
 
 (define_insn "*xordi3"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,Q")
-        (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
-                (match_operand:DI 2 "general_operand" "d,m,Q")))
+  [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,AQ,Q")
+        (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,0")
+                (match_operand:DI 2 "general_operand" "d,m,NxQD0,Q")))
    (clobber (reg:CC 33))]
   "TARGET_64BIT && s390_logical_operator_ok_p (operands)"
   "@
    xgr\t%0,%2
    xg\t%0,%2
+   #
    xc\t%O0(8,%R0),%2"
-  [(set_attr "op_type"  "RRE,RXY,SS")])
+  [(set_attr "op_type"  "RRE,RXY,SI,SS")])
+
+(define_split
+  [(set (match_operand:DI 0 "s_operand" "")
+        (xor:DI (match_dup 0) (match_operand:DI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (XOR, &operands[0], &operands[1]);")
 
 (define_expand "xordi3"
   [(set (match_operand:DI 0 "nonimmediate_operand" "")
   [(set_attr "op_type"  "RR,RX,RXY")])
 
 (define_insn "*xorsi3"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,Q")
-        (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0")
-                (match_operand:SI 2 "general_operand" "d,R,T,Q")))
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,d,AQ,Q")
+        (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,0,0,0")
+                (match_operand:SI 2 "general_operand" "d,R,T,NxQS0,Q")))
    (clobber (reg:CC 33))]
   "s390_logical_operator_ok_p (operands)"
   "@
    xr\t%0,%2
    x\t%0,%2
    xy\t%0,%2
+   #
    xc\t%O0(4,%R0),%2"
-  [(set_attr "op_type"  "RR,RX,RXY,SS")])
+  [(set_attr "op_type"  "RR,RX,RXY,SI,SS")])
+
+(define_split
+  [(set (match_operand:SI 0 "s_operand" "")
+        (xor:SI (match_dup 0) (match_operand:SI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (XOR, &operands[0], &operands[1]);")
 
 (define_expand "xorsi3"
   [(set (match_operand:SI 0 "nonimmediate_operand" "")
 ;
 
 (define_insn "*xorhi3"
-  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,Q")
-        (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
-                (match_operand:HI 2 "general_operand" "d,Q")))
+  [(set (match_operand:HI 0 "nonimmediate_operand" "=d,AQ,Q")
+        (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,0")
+                (match_operand:HI 2 "general_operand" "d,NxQH0,Q")))
    (clobber (reg:CC 33))]
   "s390_logical_operator_ok_p (operands)"
   "@
    xr\t%0,%2
+   #
    xc\t%O0(2,%R0),%2"
-  [(set_attr "op_type"  "RR,SS")])
+  [(set_attr "op_type"  "RR,SI,SS")])
+
+(define_split
+  [(set (match_operand:HI 0 "s_operand" "")
+        (xor:HI (match_dup 0) (match_operand:HI 1 "immediate_operand" "")))
+   (clobber (reg:CC 33))]
+  "reload_completed"
+  [(parallel
+    [(set (match_dup 0) (xor:QI (match_dup 0) (match_dup 1)))
+     (clobber (reg:CC 33))])]
+  "s390_narrow_logical_operator (XOR, &operands[0], &operands[1]);")
 
 (define_expand "xorhi3"
   [(set (match_operand:HI 0 "nonimmediate_operand" "")